Skip to content

Commit 824c4ed

Browse files
committed
Add test
1 parent d9a6107 commit 824c4ed

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

models_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ type Company struct {
166166

167167
type Team struct {
168168
Name string `jsonapi:"attr,name"`
169-
Leader *Employee `jsonapi:"attr,leader"`
169+
Leader Employee `jsonapi:"attr,leader"`
170170
Members []Employee `jsonapi:"attr,members"`
171171
}
172172

response_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,33 @@ func TestMarshal_InvalidIntefaceArgument(t *testing.T) {
902902
}
903903
}
904904

905+
func TestMarshalNestedStruct(t *testing.T) {
906+
team := Team{
907+
Name: "Awesome team",
908+
Leader: Employee{
909+
Firstname: "John",
910+
Surname: "Mota",
911+
Age: 35,
912+
},
913+
Members: []Employee{
914+
{
915+
Firstname: "Henrique",
916+
Surname: "Doe",
917+
},
918+
},
919+
}
920+
921+
buffer := bytes.NewBuffer(nil)
922+
MarshalOnePayloadEmbedded(buffer, &team)
923+
reader := bytes.NewReader(buffer.Bytes())
924+
var finalTeam Team
925+
UnmarshalPayload(reader, &finalTeam)
926+
927+
if !reflect.DeepEqual(team, finalTeam) {
928+
t.Error("final unmarshal payload should be equal to the original one.")
929+
}
930+
}
931+
905932
func testBlog() *Blog {
906933
return &Blog{
907934
ID: 5,

0 commit comments

Comments
 (0)