MCPcopy Create free account
hub / github.com/pace/bricks / TestMarshalPayloadWithNulls

Function TestMarshalPayloadWithNulls

http/jsonapi/response_test.go:66–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestMarshalPayloadWithNulls(t *testing.T) {
67 books := []*Book{nil, {ID: 101}, nil}
68 var jsonData map[string]interface{}
69
70 out := bytes.NewBuffer(nil)
71 if err := MarshalPayload(out, books); err != nil {
72 t.Fatal(err)
73 }
74
75 if err := json.Unmarshal(out.Bytes(), &jsonData); err != nil {
76 t.Fatal(err)
77 }
78 raw, ok := jsonData["data"]
79 if !ok {
80 t.Fatalf("data key does not exist")
81 }
82 arr, ok := raw.([]interface{})
83 if !ok {
84 t.Fatalf("data is not an Array")
85 }
86 for i := 0; i < len(arr); i++ {
87 if books[i] == nil && arr[i] != nil ||
88 books[i] != nil && arr[i] == nil {
89 t.Fatalf("restored data is not equal to source")
90 }
91 }
92}
93
94func TestMarshal_attrStringSlice(t *testing.T) {
95 tags := []string{"fiction", "sale"}

Callers

nothing calls this directly

Calls 3

MarshalPayloadFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…