break up tests

This commit is contained in:
Sam Woodard 2015-07-06 14:41:53 -07:00
parent c6b352483c
commit 99d5ee6428
1 changed files with 24 additions and 11 deletions

View File

@ -3,17 +3,7 @@ package jsonapi
import "testing" import "testing"
func TestUnmarshalSetsId(t *testing.T) { func TestUnmarshalSetsId(t *testing.T) {
in := &JsonApiPayload{ in := samplePayload()
Data: &JsonApiNode{
Id: "5",
Type: "blogs",
Attributes: map[string]interface{}{
"title": "New blog",
"created_at": 1436216820,
"view_count": 1000,
},
},
}
out := new(Blog) out := new(Blog)
if err := UnmarshalJsonApiPayload(in, out); err != nil { if err := UnmarshalJsonApiPayload(in, out); err != nil {
@ -23,6 +13,15 @@ func TestUnmarshalSetsId(t *testing.T) {
if out.Id != 5 { if out.Id != 5 {
t.Fatalf("Did not set Id on dst interface") 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() { if out.CreatedAt.IsZero() {
t.Fatalf("Did not parse time") t.Fatalf("Did not parse time")
@ -32,3 +31,17 @@ func TestUnmarshalSetsId(t *testing.T) {
t.Fatalf("View count not properly serialized") 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,
},
},
}
}