MCPcopy Create free account
hub / github.com/google/go-cloud / TestEncodeDoc

Function TestEncodeDoc

docstore/memdocstore/codec_test.go:40–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestEncodeDoc(t *testing.T) {
41 var b bool = true
42 tm := time.Now()
43 for _, test := range []struct {
44 in any
45 want storedDoc
46 }{
47 {
48 in: map[string]any{
49 "x": map[int]any{
50 1: "a",
51 2: 17,
52 3: []float32{1.0, 2.5},
53 4: map[string]bool{"false": false, "true": true},
54 },
55 },
56 want: storedDoc{
57 "x": map[string]any{
58 "1": "a",
59 "2": int64(17),
60 "3": []any{float64(1.0), float64(2.5)},
61 "4": map[string]any{"false": false, "true": true},
62 },
63 },
64 },
65 {
66 in: &aStruct{
67 X: 3,
68 embed: embed{Y: "y"},
69 Z: &b,
70 W: 33,
71 T: tm,
72 L: []int{4, 5},
73 F: 2.5,
74 B: []byte("abc"),
75 },
76 want: storedDoc{
77 "X": int64(3),
78 "Y": "y",
79 "Z": true,
80 "W": int64(33),
81 "T": tm,
82 "L": []any{int64(4), int64(5)},
83 "F": 2.5,
84 "B": []byte("abc"),
85 },
86 },
87 } {
88 doc := drivertest.MustDocument(test.in)
89 got, err := encodeDoc(doc)
90 if err != nil {
91 t.Fatal(err)
92 }
93 if diff := cmp.Diff(got, test.want); diff != "" {
94 t.Errorf("%+v: %s", test.in, diff)
95 }
96 }
97}

Callers

nothing calls this directly

Calls 2

MustDocumentFunction · 0.92
encodeDocFunction · 0.70

Tested by

no test coverage detected