(t *testing.T)
| 309 | } |
| 310 | |
| 311 | func 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 | |
| 341 | func TestMarshalOnePayload_omitIDString(t *testing.T) { |
| 342 | type Foo struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…