forked from Mirrors/jsonapi
break up tests
This commit is contained in:
parent
c6b352483c
commit
99d5ee6428
|
@ -3,17 +3,7 @@ package jsonapi
|
|||
import "testing"
|
||||
|
||||
func TestUnmarshalSetsId(t *testing.T) {
|
||||
in := &JsonApiPayload{
|
||||
Data: &JsonApiNode{
|
||||
Id: "5",
|
||||
Type: "blogs",
|
||||
Attributes: map[string]interface{}{
|
||||
"title": "New blog",
|
||||
"created_at": 1436216820,
|
||||
"view_count": 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
in := samplePayload()
|
||||
out := new(Blog)
|
||||
|
||||
if err := UnmarshalJsonApiPayload(in, out); err != nil {
|
||||
|
@ -23,6 +13,15 @@ func TestUnmarshalSetsId(t *testing.T) {
|
|||
if out.Id != 5 {
|
||||
t.Fatalf("Did not set Id on dst interface")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalSetsAttrs(t *testing.T) {
|
||||
in := samplePayload()
|
||||
out := new(Blog)
|
||||
|
||||
if err := UnmarshalJsonApiPayload(in, out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if out.CreatedAt.IsZero() {
|
||||
t.Fatalf("Did not parse time")
|
||||
|
@ -32,3 +31,17 @@ func TestUnmarshalSetsId(t *testing.T) {
|
|||
t.Fatalf("View count not properly serialized")
|
||||
}
|
||||
}
|
||||
|
||||
func samplePayload() *JsonApiPayload {
|
||||
return &JsonApiPayload{
|
||||
Data: &JsonApiNode{
|
||||
Id: "5",
|
||||
Type: "blogs",
|
||||
Attributes: map[string]interface{}{
|
||||
"title": "New blog",
|
||||
"created_at": 1436216820,
|
||||
"view_count": 1000,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue