From e22b155e5110e70e8321be9539ddfe019514a52e Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Fri, 16 Jul 2021 17:51:44 +0530 Subject: [PATCH] Resource Covered : - RepositoryAddCollaboratorOptions - RepositoryPermissionLevel - CollaboratorInvitation --- github/repos_collaborators_test.go | 181 +++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go index 07ab5e052e8..8bb6c15cf1a 100644 --- a/github/repos_collaborators_test.go +++ b/github/repos_collaborators_test.go @@ -321,3 +321,184 @@ func TestRepositoriesService_RemoveCollaborator_invalidUser(t *testing.T) { _, err := client.Repositories.RemoveCollaborator(ctx, "%", "%", "%") testURLParseError(t, err) } + +func TestRepositoryAddCollaboratorOptions_Marshal(t *testing.T) { + testJSONMarshal(t, &RepositoryAddCollaboratorOptions{}, "{}") + + r := &RepositoryAddCollaboratorOptions{ + Permission: "permission", + } + + want := `{ + "permission": "permission" + }` + + testJSONMarshal(t, r, want) +} + +func TestRepositoryPermissionLevel_Marshal(t *testing.T) { + testJSONMarshal(t, &RepositoryPermissionLevel{}, "{}") + + r := &RepositoryPermissionLevel{ + Permission: String("permission"), + User: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + } + + want := `{ + "permission": "permission", + "user": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + }` + + testJSONMarshal(t, r, want) +} + +func TestCollaboratorInvitation_Marshal(t *testing.T) { + testJSONMarshal(t, &CollaboratorInvitation{}, "{}") + + r := &CollaboratorInvitation{ + ID: Int64(1), + Repo: &Repository{ + + ID: Int64(1), + URL: String("url"), + Name: String("n"), + }, + Invitee: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + Inviter: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + Permissions: String("per"), + CreatedAt: &Timestamp{referenceTime}, + URL: String("url"), + HTMLURL: String("hurl"), + } + + want := `{ + "id": 1, + "repository": { + "id": 1, + "name": "n", + "url": "url" + }, + "invitee": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "inviter": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + }, + "permissions": "per", + "created_at": ` + referenceTimeStr + `, + "url": "url", + "html_url": "hurl" + }` + + testJSONMarshal(t, r, want) +}