Skip to content

Commit

Permalink
Add test cases for JSON resource marshaling (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harikesh00 committed Oct 26, 2022
1 parent 9b60dfb commit f9d2c6b
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions github/repos_test.go
Expand Up @@ -3002,3 +3002,84 @@ func TestAuthorizedActorsOnly_Marshal(t *testing.T) {

testJSONMarshal(t, u, want)
}

func TestDispatchRequestOptions_Marshal(t *testing.T) {
testJSONMarshal(t, &DispatchRequestOptions{}, "{}")

cp := json.RawMessage(`{"testKey":"testValue"}`)
u := &DispatchRequestOptions{
EventType: "test_event_type",
ClientPayload: &cp,
}

want := `{
"event_type": "test_event_type",
"client_payload": {
"testKey": "testValue"
}
}`

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)
}

0 comments on commit f9d2c6b

Please sign in to comment.