-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserializer_test.go
664 lines (576 loc) · 18.1 KB
/
serializer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
package fauna
import (
"context"
"encoding/base64"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type SubBusinessObj struct {
StringField string `fauna:"string_field"`
BoolField bool `fauna:"bool_field"`
MapField map[string]any `fauna:"map_field"`
SingleKeyMapField map[string]any `fauna:"single_key_map_field"`
SliceField []any `fauna:"slice_field"`
TupleField []any `fauna:"tuple_field"`
IntField int `fauna:"int_field"`
DoubleField float64 `fauna:"double_field"`
IgnoredField2 string `fauna:"-"`
}
type DocBusinessObj struct {
Document
ExtraField string `fauna:"extra_field"`
}
type NamedDocBusinessObj struct {
NamedDocument
ExtraField string `fauna:"extra_field"`
}
type NullDocBusinessObj struct {
NullDocument
}
type NullNamedDocBusinessObj struct {
NullNamedDocument
}
type BusinessObj struct {
IntField int `fauna:"int_field"`
LongField int64 `fauna:"long_field"`
DoubleField float64 `fauna:"double_field"`
PtrModField *Module `fauna:"ptr_mod_field"`
ModField Module `fauna:"mod_field"`
PtrRefField *Ref `fauna:"ptr_ref_field"`
RefField Ref `fauna:"ref_field"`
NamedRefField NamedRef `fauna:"named_ref_field"`
SetField Page `fauna:"set_field"`
StreamField EventSource `fauna:"stream_field"`
ObjField SubBusinessObj `fauna:"obj_field"`
DocField DocBusinessObj `fauna:"doc_field"`
NamedDocField NamedDocBusinessObj `fauna:"named_doc_field"`
NullDocField NullDocBusinessObj `fauna:"nulldoc_field"`
NullNamedDocField NullNamedDocBusinessObj `fauna:"nulldoc_named_field"`
BytesField []byte `fauna:"bytes_field"`
IgnoredField string `fauna:"-"`
}
func marshalAndCheck(t *testing.T, obj any) []byte {
if bs, err := marshal(obj); err != nil {
t.Fatalf("failed to marshal: %s", err)
return nil
} else {
return bs
}
}
func unmarshalAndCheck(t *testing.T, bs []byte, obj any) {
if err := unmarshal(bs, obj); err != nil {
t.Fatalf("failed to unmarshal: %s", err)
}
}
func TestRoundtrip(t *testing.T) {
var businessObjDoc = []byte(`{
"int_field": {"@int":"1234"},
"long_field": {"@long":"123456"},
"double_field": {"@double":"123.456"},
"ptr_mod_field": {"@mod":"PtrFoo"},
"mod_field": {"@mod":"Foo"},
"ptr_ref_field": {"@ref":{"id":"1234","coll":{"@mod":"PtrFoo"}}},
"ref_field": {"@ref":{"id":"1234","coll":{"@mod":"Foo:123"}}},
"named_ref_field": {"@ref":{"name":"FooBar","coll":{"@mod":"Foo"}}},
"set_field": {"@set":{"data":[0,1,2,3],"after":"foobarbaz"}},
"doc_field": {"@doc": {
"id": "1234",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"},
"extra_field": "foobar"
}},
"named_doc_field": {"@doc": {
"name": "mydoc",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"},
"extra_field": "foobar"
}},
"nulldoc_field": {"@ref":{"id":"1234","coll":{"@mod":"Foo:123"},"exists":false,"cause":"foobar"}},
"nulldoc_named_field": {"@ref":{"name":"FooBar","coll":{"@mod":"Foo"},"exists":false,"cause":"foobar"}},
"obj_field": {"@object": {
"string_field": "foobarbaz",
"bool_field": true,
"map_field": {"foo":"bar","baz":"buz"},
"single_key_map_field": {"foo":"bar"},
"slice_field": [1,2,3,4],
"tuple_field": ["one",2,3.0],
"int_field": 1234,
"double_field": 1234.567
}},
"bytes_field": {"@bytes":"SGVsbG8sIGZyb20gRmF1bmEh"}
}`)
obj := &BusinessObj{}
unmarshalAndCheck(t, businessObjDoc, obj)
bs := marshalAndCheck(t, obj)
obj2 := &BusinessObj{}
unmarshalAndCheck(t, bs, obj2)
assert.Equal(t, obj, obj2)
}
func roundTripCheck(t *testing.T, test any, expected string) {
bs := marshalAndCheck(t, test)
if assert.JSONEq(t, expected, string(bs)) {
decoded := reflect.New(reflect.TypeOf(test)).Interface()
unmarshalAndCheck(t, bs, decoded)
dec := reflect.Indirect(reflect.ValueOf(decoded)).Interface()
assert.EqualValues(t, test, dec)
}
}
func TestEncodingPrimitives(t *testing.T) {
t.Run("encode string", func(t *testing.T) {
roundTripCheck(t, "foo", `"foo"`)
})
t.Run("encode bools", func(t *testing.T) {
roundTripCheck(t, true, `true`)
roundTripCheck(t, false, `false`)
})
t.Run("encode ints", func(t *testing.T) {
roundTripCheck(t, int(10), `{"@int":"10"}`)
roundTripCheck(t, int8(10), `{"@int":"10"}`)
roundTripCheck(t, int16(10), `{"@int":"10"}`)
roundTripCheck(t, int32(10), `{"@int":"10"}`)
roundTripCheck(t, int(-10), `{"@int":"-10"}`)
roundTripCheck(t, int8(-10), `{"@int":"-10"}`)
roundTripCheck(t, int16(-10), `{"@int":"-10"}`)
roundTripCheck(t, int32(-10), `{"@int":"-10"}`)
roundTripCheck(t, 2147483647, `{"@int":"2147483647"}`)
roundTripCheck(t, -2147483648, `{"@int":"-2147483648"}`)
})
t.Run("encode longs", func(t *testing.T) {
roundTripCheck(t, 2147483648, `{"@long":"2147483648"}`)
roundTripCheck(t, -2147483649, `{"@long":"-2147483649"}`)
roundTripCheck(t, 9223372036854775807, `{"@long":"9223372036854775807"}`)
roundTripCheck(t, -9223372036854775808, `{"@long":"-9223372036854775808"}`)
})
t.Run("fail on numbers that are too big", func(t *testing.T) {
tooLarge := uint(9223372036854775808)
_, tooLargeErr := marshal(tooLarge)
assert.Error(t, tooLargeErr)
})
t.Run("encode floats", func(t *testing.T) {
roundTripCheck(t, 100.0, `{"@double":"100"}`)
roundTripCheck(t, -100.1, `{"@double":"-100.1"}`)
roundTripCheck(t, 9.999999999999, `{"@double":"9.999999999999"}`)
})
t.Run("encode nil", func(t *testing.T) {
bs := marshalAndCheck(t, nil)
if assert.JSONEq(t, `null`, string(bs)) {
var decoded *string
unmarshalAndCheck(t, bs, &decoded)
assert.Nil(t, decoded)
}
})
t.Run("encode bytes", func(t *testing.T) {
inputBytes := []byte("This is a test string 🚀 with various characters: !@#$%^&*()_+=-`~[]{}|;:'\\\",./<>?")
encoded := base64.StdEncoding.EncodeToString(inputBytes)
bs := marshalAndCheck(t, inputBytes)
if assert.JSONEq(t, `{"@bytes": "`+encoded+`"}`, string(bs)) {
var decoded []byte
unmarshalAndCheck(t, bs, &decoded)
assert.Equal(t, inputBytes, decoded)
}
})
}
func TestEncodingTime(t *testing.T) {
t.Run("encodes time as @time", func(t *testing.T) {
if tz, err := time.LoadLocation("America/Los_Angeles"); assert.NoError(t, err) {
bs := marshalAndCheck(t, time.Date(2023, 02, 28, 10, 10, 10, 10000, tz))
if assert.JSONEq(t, `{"@time":"2023-02-28T18:10:10.00001Z"}`, string(bs)) {
var decoded time.Time
bs := []byte(`{"@time":"2023-02-28T18:10:10.000010Z"}`)
unmarshalAndCheck(t, bs, &decoded)
assert.Equal(t, time.Date(2023, 02, 28, 18, 10, 10, 10000, time.UTC), decoded)
}
}
})
t.Run("encodes time as @date when hinted", func(t *testing.T) {
obj := struct {
D time.Time `fauna:"d_field,date"`
}{
D: time.Date(2023, 02, 28, 0, 0, 0, 0, time.UTC),
}
roundTripCheck(t, obj, `{"d_field":{"@date":"2023-02-28"}}`)
})
}
func TestDecodingToInterface(t *testing.T) {
var doc = []byte(`{
"int_field": {"@int":"1234"},
"long_field": {"@long":"123456"},
"double_field": {"@double":"123.456"},
"slice_field": [{"@mod":"Foo"}, {"@date":"2023-03-17"}],
"obj_field": {"@object": {
"string_field": "foobarbaz",
"bool_field": true,
"int_field": 1234,
"double_field": 1234.567
}}
}`)
var res any
err := unmarshal(doc, &res)
if assert.NoError(t, err) {
rMap := res.(map[string]any)
assert.Equal(t, int64(1234), rMap["int_field"].(int64))
assert.Equal(t, int64(123456), rMap["long_field"].(int64))
assert.Equal(t, float64(123.456), rMap["double_field"].(float64))
sliceField := rMap["slice_field"].([]any)
assert.Equal(t, &Module{"Foo"}, sliceField[0].(*Module))
sliceDate := time.Date(2023, 03, 17, 0, 0, 0, 0, time.UTC)
assert.Equal(t, &sliceDate, sliceField[1].(*time.Time))
objMap := rMap["obj_field"].(map[string]any)
assert.Equal(t, "foobarbaz", objMap["string_field"].(string))
assert.Equal(t, true, objMap["bool_field"].(bool))
assert.Equal(t, float64(1234), objMap["int_field"].(float64))
assert.Equal(t, 1234.567, objMap["double_field"].(float64))
}
}
func TestEncodingFaunaStructs(t *testing.T) {
t.Run("encodes Module", func(t *testing.T) {
obj := Module{"Foo"}
roundTripCheck(t, obj, `{"@mod":"Foo"}`)
})
t.Run("encodes Ref", func(t *testing.T) {
obj := Ref{"1234", &Module{"Foo"}}
roundTripCheck(t, obj, `{"@ref":{"id":"1234","coll":{"@mod":"Foo"}}}`)
})
t.Run("encodes NamedRef", func(t *testing.T) {
obj := NamedRef{"Bar", &Module{"Foo"}}
roundTripCheck(t, obj, `{"@ref":{"name":"Bar","coll":{"@mod":"Foo"}}}`)
})
t.Run("encodes Page", func(t *testing.T) {
obj := Page{[]any{"0", "1", "2"}, "foobarbaz"}
roundTripCheck(t, obj, `{"@set":{"data":["0","1","2"],"after":"foobarbaz"}}`)
})
t.Run("encodes StreamFromQuery", func(t *testing.T) {
stream := EventSource("abcd==")
roundTripCheck(t, stream, `{"@stream":"abcd=="}`)
})
t.Run("encode NullDoc", func(t *testing.T) {
obj := NullDocument{Cause: "Foo", Ref: &Ref{ID: "1234", Coll: &Module{"Foo"}}}
roundTripCheck(t, obj, `{"cause": "Foo", "ref": {"@ref":{"id":"1234","coll":{"@mod":"Foo"}}}}`)
})
t.Run("decodes data-less set", func(t *testing.T) {
bs := []byte(`{"@set":"foobarbaz"}`)
var set any
unmarshalAndCheck(t, bs, &set)
if page, ok := set.(*Page); assert.True(t, ok) {
assert.Nil(t, page.Data)
assert.Equal(t, "foobarbaz", page.After)
}
})
}
func TestEncodingStructs(t *testing.T) {
t.Run("encodes using struct field names", func(t *testing.T) {
obj := struct {
Field string
}{"foo"}
roundTripCheck(t, obj, `{"Field":"foo"}`)
})
t.Run("encodes using configured field names", func(t *testing.T) {
obj := struct {
Field string `fauna:"field_name"`
}{"foo"}
roundTripCheck(t, obj, `{"field_name":"foo"}`)
})
t.Run("encodes hinted types without configured name", func(t *testing.T) {
obj := struct {
Field time.Time `fauna:",date"`
}{
Field: time.Date(2023, 02, 28, 0, 0, 0, 0, time.UTC),
}
roundTripCheck(t, obj, `{"Field":{"@date":"2023-02-28"}}`)
})
t.Run("encodes hinted types with configured name", func(t *testing.T) {
obj := struct {
Field time.Time `fauna:"field_name,date"`
}{
Field: time.Date(2023, 02, 28, 0, 0, 0, 0, time.UTC),
}
roundTripCheck(t, obj, `{"field_name":{"@date":"2023-02-28"}}`)
})
t.Run("ignores fields", func(t *testing.T) {
obj := struct {
Field string
IgnoredField string `fauna:"-"`
}{
Field: "foo",
IgnoredField: "",
}
roundTripCheck(t, obj, `{"Field":"foo"}`)
})
t.Run("encodes nested fields", func(t *testing.T) {
var obj struct {
GrandParent struct {
Parent struct {
Child string
Sibling string
}
}
}
obj.GrandParent.Parent.Child = "foo"
obj.GrandParent.Parent.Sibling = "bar"
roundTripCheck(t, obj, `{"GrandParent":{"Parent":{"Child":"foo","Sibling":"bar"}}}`)
})
}
func TestEncodingPointers(t *testing.T) {
type checkStruct struct {
Field string
}
var obj struct {
NilPtrField *checkStruct
PtrField *checkStruct
Field checkStruct
}
obj.NilPtrField = nil
obj.PtrField = &checkStruct{"foo"}
obj.Field = checkStruct{"bar"}
roundTripCheck(t, obj, `{"NilPtrField":null,"PtrField":{"Field":"foo"},"Field":{"Field":"bar"}}`)
}
func TestEncodingObject(t *testing.T) {
t.Run("object has @object key", func(t *testing.T) {
test := map[string]int{"@object": 10}
expected := `{"@object":{"@object":{"@int":"10"}}}`
bs := marshalAndCheck(t, test)
assert.JSONEq(t, expected, string(bs))
})
t.Run("object has inner conflicting @int key", func(t *testing.T) {
roundTripCheck(
t,
map[string]map[string]string{"@object": {"@int": "bar"}},
`{"@object":{"@object":{"@object":{"@int":"bar"}}}}`,
)
})
t.Run("object has inner conflicting @object key", func(t *testing.T) {
roundTripCheck(
t,
map[string]map[string]string{"@object": {"@object": "bar"}},
`{"@object":{"@object":{"@object":{"@object":"bar"}}}}`,
)
})
t.Run("object has multiple conflicting type keys", func(t *testing.T) {
roundTripCheck(
t,
map[string]string{"@int": "foo", "@double": "bar"},
`{"@object":{"@int":"foo","@double":"bar"}}`,
)
})
t.Run("object has mixed keys with a conflict", func(t *testing.T) {
roundTripCheck(
t,
map[string]string{"@int": "foo", "bar": "buz"},
`{"@object":{"@int":"foo","bar":"buz"}}`,
)
})
t.Run("object has nested conflicting keys", func(t *testing.T) {
roundTripCheck(
t,
map[string]map[string]map[string]map[string]int{"@int": {"@date": {"@time": {"@long": 10}}}},
`{"@object":{"@int":{"@object":{"@date":{"@object":{"@time":{"@object":{"@long":{"@int":"10"}}}}}}}}}`,
)
})
t.Run("object has non-conflicting keys", func(t *testing.T) {
roundTripCheck(
t,
map[string]int{"@foo": 10},
`{"@foo":{"@int":"10"}}`,
)
})
}
func TestEncodingDocuments(t *testing.T) {
t.Run("Document", func(t *testing.T) {
type MyDoc struct {
Document
ExtraField1 string `fauna:"extra_field_1"`
ExtraField2 string `fauna:"extra_field_2"`
}
doc := []byte(`{"@doc":{
"id": "1234",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.000010Z"},
"extra_field_1": "foobar",
"extra_field_2": "bazbuz"
}}`)
ts := time.Date(2023, 02, 28, 18, 10, 10, 10000, time.UTC)
expected := MyDoc{
Document: Document{
ID: "1234",
Coll: &Module{"Foo"},
TS: &ts,
},
ExtraField1: "foobar",
ExtraField2: "bazbuz",
}
var got MyDoc
unmarshalAndCheck(t, doc, &got)
assert.Equal(t, expected, got)
encodedDoc := `{"@doc":{
"id": "1234",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"},
"extra_field_1": "foobar",
"extra_field_2": "bazbuz"
}}`
bs := marshalAndCheck(t, expected)
assert.JSONEq(t, encodedDoc, string(bs))
})
t.Run("NamedDocument", func(t *testing.T) {
type MyDoc struct {
NamedDocument
ExtraField1 string `fauna:"extra_field_1"`
ExtraField2 string `fauna:"extra_field_2"`
}
doc := []byte(`{"@doc":{
"name": "mydoc",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.000010Z"},
"extra_field_1": "foobar",
"extra_field_2": "bazbuz"
}}`)
ts := time.Date(2023, 02, 28, 18, 10, 10, 10000, time.UTC)
expected := MyDoc{
NamedDocument: NamedDocument{
Name: "mydoc",
Coll: &Module{"Foo"},
TS: &ts,
},
ExtraField1: "foobar",
ExtraField2: "bazbuz",
}
var got MyDoc
unmarshalAndCheck(t, doc, &got)
assert.Equal(t, expected, got)
encodedDoc := `{"@doc":{
"name": "mydoc",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"},
"extra_field_1": "foobar",
"extra_field_2": "bazbuz"
}}`
bs := marshalAndCheck(t, expected)
assert.JSONEq(t, encodedDoc, string(bs))
})
t.Run("Raw Document", func(t *testing.T) {
doc := []byte(`{"@doc":{
"id": "1234",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.000010Z"}
}}`)
ts := time.Date(2023, 02, 28, 18, 10, 10, 10000, time.UTC)
expected := Document{
ID: "1234",
Coll: &Module{"Foo"},
TS: &ts,
}
var got Document
unmarshalAndCheck(t, doc, &got)
assert.Equal(t, expected, got)
encodedDoc := `{"@doc":{
"id": "1234",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"}
}}`
bs := marshalAndCheck(t, expected)
assert.JSONEq(t, encodedDoc, string(bs))
})
t.Run("Raw NamedDocument", func(t *testing.T) {
doc := []byte(`{"@doc":{
"name": "mydoc",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.000010Z"}
}}`)
ts := time.Date(2023, 02, 28, 18, 10, 10, 10000, time.UTC)
expected := NamedDocument{
Name: "mydoc",
Coll: &Module{"Foo"},
TS: &ts,
}
var got NamedDocument
unmarshalAndCheck(t, doc, &got)
assert.Equal(t, expected, got)
encodedDoc := `{"@doc":{
"name": "mydoc",
"coll": {"@mod":"Foo"},
"ts": {"@time":"2023-02-28T18:10:10.00001Z"}
}}`
bs := marshalAndCheck(t, expected)
assert.JSONEq(t, encodedDoc, string(bs))
})
}
func TestComposition(t *testing.T) {
testDate := time.Date(2023, 2, 24, 0, 0, 0, 0, time.UTC)
testDino := map[string]any{
"name": "Dino",
"age": 0,
"birthdate": testDate,
}
testInnerDino, err := FQL("let x = ${my_var}", map[string]any{"my_var": testDino})
t.Run("template variable", func(t *testing.T) {
encodedDoc := `{"fql":[
"let x = ",
{"value":{
"age":{"@int":"0"},
"birthdate":{"@time":"2023-02-24T00:00:00Z"},
"name":"Dino"
}}
]}`
if assert.NoError(t, err) {
bs := marshalAndCheck(t, testInnerDino)
assert.JSONEq(t, encodedDoc, string(bs))
}
})
t.Run("sub query", func(t *testing.T) {
encodedDoc := `{"fql":[
{"fql":[
"let x = ",
{"value":{
"age":{"@int":"0"},
"birthdate":{"@time":"2023-02-24T00:00:00Z"},
"name":"Dino"
}}
]},
"\nx { name }"
]}`
if assert.NoError(t, err) {
inner, err := FQL("${inner}\nx { name }", map[string]any{"inner": testInnerDino})
if assert.NoError(t, err) {
bs := marshalAndCheck(t, inner)
assert.JSONEq(t, encodedDoc, string(bs))
}
}
})
}
func TestMarshalEventSourceStructs(t *testing.T) {
t.Run("marshal query request", func(t *testing.T) {
marshalAndCheck(t, queryRequest{
apiRequest: apiRequest{
Context: context.Background(),
Headers: map[string]string{},
},
Query: nil,
Arguments: nil,
})
})
t.Run("marshal stream request", func(t *testing.T) {
marshalAndCheck(t, streamRequest{
apiRequest: apiRequest{
Context: context.Background(),
Headers: map[string]string{},
},
Stream: "",
StartTS: 0,
Cursor: "",
})
})
t.Run("marshal feed request", func(t *testing.T) {
marshalAndCheck(t, feedRequest{
apiRequest: apiRequest{
Context: context.Background(),
Headers: map[string]string{},
},
Source: "",
Cursor: "",
PageSize: 0,
StartTS: 0,
})
})
}