From 99d5ee6428396d7a664dd63877aa7352097d0b40 Mon Sep 17 00:00:00 2001 From: Sam Woodard Date: Mon, 6 Jul 2015 14:41:53 -0700 Subject: [PATCH] break up tests --- request_test.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/request_test.go b/request_test.go index a56c0bb..e15f6cc 100644 --- a/request_test.go +++ b/request_test.go @@ -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, + }, + }, + } +}