MCPcopy
hub / github.com/google/uuid / TestNullUUIDMarshalJSON

Function TestNullUUIDMarshalJSON

null_test.go:168–199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestNullUUIDMarshalJSON(t *testing.T) {
169 jsonNull, _ := json.Marshal(nil)
170 jsonUUID, _ := json.Marshal(MustParse("12345678-abcd-1234-abcd-0123456789ab"))
171 tests := []struct {
172 nullUUID NullUUID
173 expected []byte
174 expectedErr error
175 }{
176 {
177 nullUUID: NullUUID{},
178 expected: jsonNull,
179 expectedErr: nil,
180 },
181 {
182 nullUUID: NullUUID{
183 UUID: MustParse(string(jsonUUID)),
184 Valid: true,
185 },
186 expected: []byte(`"12345678-abcd-1234-abcd-0123456789ab"`),
187 expectedErr: nil,
188 },
189 }
190 for _, test := range tests {
191 data, err := json.Marshal(&test.nullUUID)
192 if err != test.expectedErr {
193 t.Errorf("expected error %e, got %e", test.expectedErr, err)
194 }
195 if !bytes.Equal(data, test.expected) {
196 t.Errorf("expected json data %s, got %s", string(test.expected), string(data))
197 }
198 }
199}
200
201func TestNullUUIDUnmarshalJSON(t *testing.T) {
202 jsonNull, _ := json.Marshal(nil)

Callers

nothing calls this directly

Calls 1

MustParseFunction · 0.85

Tested by

no test coverage detected