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

Function TestMarshalOnePayload_omitIDString

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

Source from the content-addressed store, hash-verified

339}
340
341func TestMarshalOnePayload_omitIDString(t *testing.T) {
342 type Foo struct {
343 ID string `jsonapi:"primary,foo"`
344 Title string `jsonapi:"attr,title"`
345 }
346
347 foo := &Foo{Title: "Foo"}
348 out := bytes.NewBuffer(nil)
349 if err := MarshalPayload(out, foo); err != nil {
350 t.Fatal(err)
351 }
352
353 var jsonData map[string]interface{}
354 if err := json.Unmarshal(out.Bytes(), &jsonData); err != nil {
355 t.Fatal(err)
356 }
357 payload := jsonData["data"].(map[string]interface{})
358
359 // Verify that empty ID of type string gets omitted. See:
360 // https://github.com/google/jsonapi/issues/83#issuecomment-285611425
361 _, ok := payload["id"]
362 if ok {
363 t.Fatal("Was expecting the data.id member to be omitted")
364 }
365}
366
367func TestMarshall_invalidIDType(t *testing.T) {
368 type badIDStruct struct {

Callers

nothing calls this directly

Calls 2

MarshalPayloadFunction · 0.85
FatalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…