From 0ad4844f5b5ab450654fda51125f625a3b9a0353 Mon Sep 17 00:00:00 2001 From: Harikesh Prajapati Date: Tue, 25 Oct 2022 14:20:28 +0530 Subject: [PATCH 1/3] Added test cases for JSON resource marshaling --- github/repos_test.go | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/github/repos_test.go b/github/repos_test.go index ec32b5d578d..89179aed6bb 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -3002,3 +3002,80 @@ func TestAuthorizedActorsOnly_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestDispatchRequestOptions_Marshal(t *testing.T) { + testJSONMarshal(t, &DispatchRequestOptions{}, "{}") + + u := &DispatchRequestOptions{ + EventType: "test_event_type", + } + + want := `{ + "event_type":"test_event_type", + "client_payload":null + }` + + testJSONMarshal(t, u, want) +} + +func TestTransferRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &TransferRequest{}, "{}") + + u := &TransferRequest{ + NewOwner: "testOwner", + TeamID: []int64{1, 2}, + } + + want := `{ + "new_owner":"testOwner", + "team_ids":[1,2] + }` + + testJSONMarshal(t, u, want) +} + +func TestSignaturesProtectedBranch_Marshal(t *testing.T) { + testJSONMarshal(t, &SignaturesProtectedBranch{}, "{}") + + u := &SignaturesProtectedBranch{ + URL: String("https://www.testURL.in"), + Enabled: Bool(false), + } + + want := `{ + "url":"https://www.testURL.in", + "enabled":false + }` + + testJSONMarshal(t, u, want) + + u2 := &SignaturesProtectedBranch{ + URL: String("testURL"), + Enabled: Bool(true), + } + + want2 := `{ + "url":"testURL", + "enabled":true + }` + + testJSONMarshal(t, u2, want2) +} + +func TestDismissalRestrictionsRequest_Marshal(t *testing.T) { + testJSONMarshal(t, &DismissalRestrictionsRequest{}, "{}") + + u := &DismissalRestrictionsRequest{ + Users: &[]string{"user1", "user2"}, + Teams: &[]string{"team1", "team2"}, + Apps: &[]string{"app1", "app2"}, + } + + want := `{ + "users":["user1","user2"], + "teams":["team1","team2"], + "apps":["app1","app2"] + }` + + testJSONMarshal(t, u, want) +} From 84a66e16531c6bac0841e44c0a52ff783c8b149b Mon Sep 17 00:00:00 2001 From: Harikesh Prajapati Date: Tue, 25 Oct 2022 23:01:36 +0530 Subject: [PATCH 2/3] simulated client payload --- github/repos_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/github/repos_test.go b/github/repos_test.go index 89179aed6bb..a689b93d24c 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -3006,13 +3006,17 @@ func TestAuthorizedActorsOnly_Marshal(t *testing.T) { func TestDispatchRequestOptions_Marshal(t *testing.T) { testJSONMarshal(t, &DispatchRequestOptions{}, "{}") + cp := json.RawMessage(`{"testKey":"testValue"}`) u := &DispatchRequestOptions{ - EventType: "test_event_type", + EventType: "test_event_type", + ClientPayload: &cp, } want := `{ "event_type":"test_event_type", - "client_payload":null + "client_payload":{ + "testKey":"testValue" + } }` testJSONMarshal(t, u, want) From bfa9bee28c68f247f690653631f972433010e33a Mon Sep 17 00:00:00 2001 From: Harikesh Prajapati Date: Tue, 25 Oct 2022 23:01:36 +0530 Subject: [PATCH 3/3] simulated client payload --- github/repos_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/github/repos_test.go b/github/repos_test.go index 89179aed6bb..0a3adc103cb 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -3006,14 +3006,18 @@ func TestAuthorizedActorsOnly_Marshal(t *testing.T) { func TestDispatchRequestOptions_Marshal(t *testing.T) { testJSONMarshal(t, &DispatchRequestOptions{}, "{}") + cp := json.RawMessage(`{"testKey":"testValue"}`) u := &DispatchRequestOptions{ - EventType: "test_event_type", + EventType: "test_event_type", + ClientPayload: &cp, } want := `{ - "event_type":"test_event_type", - "client_payload":null - }` + "event_type": "test_event_type", + "client_payload": { + "testKey": "testValue" + } + }` testJSONMarshal(t, u, want) }