(t *testing.T)
| 380 | } |
| 381 | |
| 382 | func TestOmitsEmptyAnnotation(t *testing.T) { |
| 383 | book := &Book{ |
| 384 | Author: "aren55555", |
| 385 | PublishedAt: time.Now().AddDate(0, -1, 0), |
| 386 | } |
| 387 | |
| 388 | out := bytes.NewBuffer(nil) |
| 389 | if err := MarshalPayload(out, book); err != nil { |
| 390 | t.Fatal(err) |
| 391 | } |
| 392 | |
| 393 | var jsonData map[string]interface{} |
| 394 | if err := json.Unmarshal(out.Bytes(), &jsonData); err != nil { |
| 395 | t.Fatal(err) |
| 396 | } |
| 397 | attributes := jsonData["data"].(map[string]interface{})["attributes"].(map[string]interface{}) |
| 398 | |
| 399 | // Verify that the specifically omitted field were omitted |
| 400 | if val, exists := attributes["title"]; exists { |
| 401 | t.Fatalf("Was expecting the data.attributes.title key/value to have been omitted - it was not and had a value of %v", val) |
| 402 | } |
| 403 | if val, exists := attributes["pages"]; exists { |
| 404 | t.Fatalf("Was expecting the data.attributes.pages key/value to have been omitted - it was not and had a value of %v", val) |
| 405 | } |
| 406 | |
| 407 | // Verify the implicitly omitted fields were omitted |
| 408 | if val, exists := attributes["PublishedAt"]; exists { |
| 409 | t.Fatalf("Was expecting the data.attributes.PublishedAt key/value to have been implicitly omitted - it was not and had a value of %v", val) |
| 410 | } |
| 411 | |
| 412 | // Verify the unset fields were not omitted |
| 413 | if _, exists := attributes["isbn"]; !exists { |
| 414 | t.Fatal("Was expecting the data.attributes.isbn key/value to have NOT been omitted") |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | func TestHasPrimaryAnnotation(t *testing.T) { |
| 419 | testModel := &Blog{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…