Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for JSON resource marshaling #2520

Merged
merged 10 commits into from Oct 26, 2022
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)
}