From 5067660024599d0d05ff708ccd3f868c65545403 Mon Sep 17 00:00:00 2001 From: Sagar Sonwane <44731466+sagar23sj@users.noreply.github.com> Date: Fri, 9 Jul 2021 01:18:41 +0530 Subject: [PATCH] Add test cases for JSON resource marshaling (#1902) --- github/event_types_test.go | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/github/event_types_test.go b/github/event_types_test.go index 3116a2c4c00..5246a0028cc 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -80,3 +80,93 @@ func TestEditChange_Marshal_BaseChange(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestProjectChange_Marshal_NameChange(t *testing.T) { + testJSONMarshal(t, &ProjectChange{}, "{}") + + NameFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NameFrom"), + } + + u := &ProjectChange{ + Name: &NameFrom, + Body: nil, + } + + want := `{ + "name": { + "from": "NameFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectChange_Marshal_BodyChange(t *testing.T) { + testJSONMarshal(t, &ProjectChange{}, "{}") + + BodyFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("BodyFrom"), + } + + u := &ProjectChange{ + Name: nil, + Body: &BodyFrom, + } + + want := `{ + "body": { + "from": "BodyFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectCardChange_Marshal_NoteChange(t *testing.T) { + testJSONMarshal(t, &ProjectCardChange{}, "{}") + + NoteFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NoteFrom"), + } + + u := &ProjectCardChange{ + Note: &NoteFrom, + } + + want := `{ + "note": { + "from": "NoteFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectColumnChange_Marshal_NameChange(t *testing.T) { + testJSONMarshal(t, &ProjectColumnChange{}, "{}") + + NameFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NameFrom"), + } + + u := &ProjectColumnChange{ + Name: &NameFrom, + } + + want := `{ + "name": { + "from": "NameFrom" + } + }` + + testJSONMarshal(t, u, want) +}