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

Function TestMarshalIDPtr

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

Source from the content-addressed store, hash-verified

309}
310
311func TestMarshalIDPtr(t *testing.T) {
312 id, make, model := "123e4567-e89b-12d3-a456-426655440000", "Ford", "Mustang"
313 car := &Car{
314 ID: &id,
315 Make: &make,
316 Model: &model,
317 }
318
319 out := bytes.NewBuffer(nil)
320 if err := MarshalPayload(out, car); err != nil {
321 t.Fatal(err)
322 }
323
324 var jsonData map[string]interface{}
325 if err := json.Unmarshal(out.Bytes(), &jsonData); err != nil {
326 t.Fatal(err)
327 }
328 data := jsonData["data"].(map[string]interface{})
329 // attributes := data["attributes"].(map[string]interface{})
330
331 // Verify that the ID was sent
332 val, exists := data["id"]
333 if !exists {
334 t.Fatal("Was expecting the data.id member to exist")
335 }
336 if val != id {
337 t.Fatalf("Was expecting the data.id member to be `%s`, got `%s`", id, val)
338 }
339}
340
341func TestMarshalOnePayload_omitIDString(t *testing.T) {
342 type Foo struct {

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…