From 0fc28f5ca3679a630c0e85afa1170c55b05978ea Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 01:40:09 +0530 Subject: [PATCH 01/10] pulls_comments_test.go: test case for JSON marshalling --- github/pulls_comments_test.go | 100 ++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index 76b78cf71b1..895507a50ac 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -15,6 +15,106 @@ import ( "time" ) +func TestPullComments_marshall(t *testing.T) { + testJSONMarshal(t, &PullRequestComment{}, "{}") + + createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC) + updatedAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC) + reactions := &Reactions{ + TotalCount: Int(1), + PlusOne: Int(1), + MinusOne: Int(0), + Laugh: Int(0), + Confused: Int(0), + Heart: Int(0), + Hooray: Int(0), + URL: String("u"), + } + + u := &PullRequestComment{ + ID: Int64(10), + InReplyTo: Int64(8), + Body: String("Test comment"), + Path: String("file1.txt"), + DiffHunk: String("@@ -16,33 +16,40 @@ fmt.Println()"), + PullRequestReviewID: Int64(42), + Position: Int(1), + OriginalPosition: Int(4), + CommitID: String("ab"), + OriginalCommitID: String("9c"), + User: &User{ + Login: String("ll"), + ID: Int64(123), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + URL: String("u"), + }, + Reactions: reactions, + CreatedAt: &createdAt, + UpdatedAt: &updatedAt, + URL: String("pullrequestcommentUrl"), + HTMLURL: String("pullrequestcommentHTMLUrl"), + PullRequestURL: String("pullrequestcommentPullRequestURL"), + } + + want := `{ + "id": 10, + "in_reply_to_id": 8, + "body": "Test comment", + "path": "file1.txt", + "diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()", + "pull_request_review_id": 42, + "position": 1, + "original_position": 4, + "commit_id": "ab", + "original_commit_id": "9c", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "reactions": { + "total_count": 1, + "+1": 1, + "-1": 0, + "laugh": 0, + "confused": 0, + "heart": 0, + "hooray": 0, + "url": "u" + }, + "created_at": "2002-02-10T15:30:00Z", + "updated_at": "2002-02-10T15:30:00Z", + "url": "pullrequestcommentUrl", + "html_url": "pullrequestcommentHTMLUrl", + "pull_request_url": "pullrequestcommentPullRequestURL" + }` + + testJSONMarshal(t, u, want) +} + func TestPullRequestsService_ListComments_allPulls(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From b35bedc1dc6cab2159a3b203a040457b985c6a10 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 02:09:32 +0530 Subject: [PATCH 02/10] gists_comments_test.go: test case for JSON marshalling --- github/gists_comments_test.go | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index d2f5a9534c7..97c02df1398 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -12,8 +12,64 @@ import ( "net/http" "reflect" "testing" + "time" ) +func TestGistComments_marshall(t *testing.T) { + testJSONMarshal(t, &GistComment{}, "{}") + + createdAt := time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC) + + u := &GistComment{ + ID: Int64(1), + URL: String("u"), + Body: String("test gist comment"), + User: &User{ + Login: String("ll"), + ID: Int64(123), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + URL: String("u"), + }, + CreatedAt: &createdAt, + } + + want := `{ + "id": 1, + "url": "u", + "body": "test gist comment", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "created_at": "2002-02-10T15:30:00Z", + }` + + testJSONMarshal(t, u, want) +} func TestGistsService_ListComments(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From 8a865bd86e1f13a18f43b1ed2f4f6fb422d4e46d Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 02:12:49 +0530 Subject: [PATCH 03/10] fix json error --- github/gists_comments_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index 97c02df1398..21ce22a68c7 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -65,7 +65,7 @@ func TestGistComments_marshall(t *testing.T) { "created_at": ` + referenceTimeStr + `, "url": "u" }, - "created_at": "2002-02-10T15:30:00Z", + "created_at": "2002-02-10T15:30:00Z" }` testJSONMarshal(t, u, want) From 6a3b21f9dbdda1d3d433377909717dc0c07318e0 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 03:03:38 +0530 Subject: [PATCH 04/10] gists_test.go: test case for JSON marshalling --- github/gists_test.go | 212 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) diff --git a/github/gists_test.go b/github/gists_test.go index 3d31c9acafb..6026a6a743a 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -15,6 +15,218 @@ import ( "time" ) +func TestGist_marshall(t *testing.T) { + testJSONMarshal(t, &Gist{}, "{}") + + createdAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) + updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) + + u := &Gist{ + ID: Int64(1), + Description: String("description"), + Public: Bool(true), + Owner: &User{ + Login: String("ll"), + ID: Int64(123), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + URL: String("u"), + }, + Files: map[GistFilename]GistFile{ + String("gistfile.py"): &GistFile{ + Size: Int(167), + Filename: String("gistfile.py"), + Language: String("Python"), + Type: String("application/x-python"), + RawURL: String("raw-url"), + Content: String("c"), + }, + }, + Comments: Int(1), + HTMLURL: String("html-url"), + GitPullURL: String("gitpull-url"), + GitPushURL: String("gitpush-url"), + CreatedAt: &createdAt, + UpdatedAt: &updatedAt, + NodeID: String("node"), + } + + want := `{ + "id": 1, + "description": "description", + "public": true, + "owner": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "files": { + "gistfile.py": { + "size": 167, + "filename": "gistfile.py", + "language": "Python", + "type": "application/x-python", + "raw_url": "raw-url", + "content": "c" + } + }, + "comments": 1, + "html_url": "html-url", + "git_pull_url": "gitpull-url", + "git_push_url": "gitpush-url", + "created_at": "2010-02-10T10:10:00Z", + "updated_at": "2010-02-10T10:10:00Z", + "node_id": "node" + }` + + testJSONMarshal(t, u, want) +} + +func TestGistCommit_marshall(t *testing.T) { + testJSONMarshal(t, &GistCommit{}, "{}") + + committedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) + + u := &GistCommit{ + URL: String("u"), + Version: String("v"), + User: &User{ + Login: String("ll"), + ID: Int64(123), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + URL: String("u"), + }, + ChangeStatus: &CommentStats{ + Additions: Int(1), + Deletions: Int(1), + Total: Int(2), + }, + CommittedAt: &committedAt, + NodeID: String("node"), + } + + want := `{ + "url": "u", + "version": "v", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "change_status": { + "additions": 1, + "deletions": 1, + "total": 2 + }, + "committed_at": "2010-02-10T10:10:00Z", + "node_id": "node" + }` + + testJSONMarshal(t, u, want) +} + +func TestGistFork_marshall(t *testing.T) { + testJSONMarshal(t, &GistFork{}, "{}") + + createdAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) + updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) + + u := &GistFork{ + URL: String("u"), + User: &User{ + Login: String("ll"), + ID: Int64(123), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + URL: String("u"), + }, + ID: String("id"), + CreatedAt: &createdAt, + UpdatedAt: &updatedAt, + NodeID: String("node"), + } + + want := `{ + "url": "u", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "id": 1, + "created_at": "2010-02-10T10:10:00Z", + "updated_at": "2010-02-10T10:10:00Z", + "node_id": "node" + }` +} + func TestGistsService_List_specifiedUser(t *testing.T) { client, mux, _, teardown := setup() defer teardown() From ef4f7bd238e4556b061ab25150bc698107392c8e Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 03:33:17 +0530 Subject: [PATCH 05/10] fixed travis error --- github/gists_test.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/github/gists_test.go b/github/gists_test.go index 6026a6a743a..b30e83291c0 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -22,7 +22,7 @@ func TestGist_marshall(t *testing.T) { updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) u := &Gist{ - ID: Int64(1), + ID: String("i"), Description: String("description"), Public: Bool(true), Owner: &User{ @@ -42,7 +42,7 @@ func TestGist_marshall(t *testing.T) { CreatedAt: &Timestamp{referenceTime}, URL: String("u"), }, - Files: map[GistFilename]GistFile{ + Files: map[*GistFilename]GistFile{ String("gistfile.py"): &GistFile{ Size: Int(167), Filename: String("gistfile.py"), @@ -62,7 +62,7 @@ func TestGist_marshall(t *testing.T) { } want := `{ - "id": 1, + "id": "i", "description": "description", "public": true, "owner": { @@ -107,8 +107,6 @@ func TestGist_marshall(t *testing.T) { func TestGistCommit_marshall(t *testing.T) { testJSONMarshal(t, &GistCommit{}, "{}") - committedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) - u := &GistCommit{ URL: String("u"), Version: String("v"), @@ -129,12 +127,12 @@ func TestGistCommit_marshall(t *testing.T) { CreatedAt: &Timestamp{referenceTime}, URL: String("u"), }, - ChangeStatus: &CommentStats{ + ChangeStatus: &CommitStats{ Additions: Int(1), Deletions: Int(1), Total: Int(2), }, - CommittedAt: &committedAt, + CommittedAt: &Timestamp{referenceTime}, NodeID: String("node"), } @@ -163,7 +161,7 @@ func TestGistCommit_marshall(t *testing.T) { "deletions": 1, "total": 2 }, - "committed_at": "2010-02-10T10:10:00Z", + "committed_at": ` + referenceTimeStr + `, "node_id": "node" }` @@ -173,9 +171,6 @@ func TestGistCommit_marshall(t *testing.T) { func TestGistFork_marshall(t *testing.T) { testJSONMarshal(t, &GistFork{}, "{}") - createdAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) - updatedAt := time.Date(2010, time.February, 10, 10, 10, 0, 0, time.UTC) - u := &GistFork{ URL: String("u"), User: &User{ @@ -196,8 +191,8 @@ func TestGistFork_marshall(t *testing.T) { URL: String("u"), }, ID: String("id"), - CreatedAt: &createdAt, - UpdatedAt: &updatedAt, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, NodeID: String("node"), } @@ -221,8 +216,8 @@ func TestGistFork_marshall(t *testing.T) { "url": "u" }, "id": 1, - "created_at": "2010-02-10T10:10:00Z", - "updated_at": "2010-02-10T10:10:00Z", + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, "node_id": "node" }` } From 201b809850cde861d1454394f8b875445e027e6c Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 03:53:56 +0530 Subject: [PATCH 06/10] fixed travis error --- github/gists_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/gists_test.go b/github/gists_test.go index b30e83291c0..2e4a9654326 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -42,8 +42,8 @@ func TestGist_marshall(t *testing.T) { CreatedAt: &Timestamp{referenceTime}, URL: String("u"), }, - Files: map[*GistFilename]GistFile{ - String("gistfile.py"): &GistFile{ + Files: map[GistFilename]GistFile{ + "gistfile.py": GistFile{ Size: Int(167), Filename: String("gistfile.py"), Language: String("Python"), From e48e710e85631906c488768e240ee24a07817d89 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 03:57:55 +0530 Subject: [PATCH 07/10] fixed travis error --- github/gists_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/github/gists_test.go b/github/gists_test.go index 2e4a9654326..78d70c8f439 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -220,6 +220,8 @@ func TestGistFork_marshall(t *testing.T) { "updated_at": ` + referenceTimeStr + `, "node_id": "node" }` + + testJSONMarshal(t, u, want) } func TestGistsService_List_specifiedUser(t *testing.T) { From 72946e74e04eccffa9d0ec5e904198197b4d2925 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 04:15:21 +0530 Subject: [PATCH 08/10] fixed travis error --- github/gists_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/gists_test.go b/github/gists_test.go index 78d70c8f439..43f98a4b271 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -215,7 +215,7 @@ func TestGistFork_marshall(t *testing.T) { "created_at": ` + referenceTimeStr + `, "url": "u" }, - "id": 1, + "id": "id", "created_at": ` + referenceTimeStr + `, "updated_at": ` + referenceTimeStr + `, "node_id": "node" From 2b5b66446f775ec65fc651f89080941f01b244a3 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 18:48:32 +0530 Subject: [PATCH 09/10] fixed formatting of code --- github/gists_comments_test.go | 42 +++++++++--------- github/pulls_comments_test.go | 84 +++++++++++++++++------------------ 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index 21ce22a68c7..b4345c40a71 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -45,27 +45,27 @@ func TestGistComments_marshall(t *testing.T) { } want := `{ - "id": 1, - "url": "u", - "body": "test gist comment", - "user": { - "login": "ll", - "id": 123, - "avatar_url": "a", - "gravatar_id": "g", - "name": "n", - "company": "c", - "blog": "b", - "location": "l", - "email": "e", - "hireable": true, - "public_repos": 1, - "followers": 1, - "following": 1, - "created_at": ` + referenceTimeStr + `, - "url": "u" - }, - "created_at": "2002-02-10T15:30:00Z" + "id": 1, + "url": "u", + "body": "test gist comment", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "created_at": "2002-02-10T15:30:00Z" }` testJSONMarshal(t, u, want) diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index 895507a50ac..b07b2cd99b0 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -68,48 +68,48 @@ func TestPullComments_marshall(t *testing.T) { } want := `{ - "id": 10, - "in_reply_to_id": 8, - "body": "Test comment", - "path": "file1.txt", - "diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()", - "pull_request_review_id": 42, - "position": 1, - "original_position": 4, - "commit_id": "ab", - "original_commit_id": "9c", - "user": { - "login": "ll", - "id": 123, - "avatar_url": "a", - "gravatar_id": "g", - "name": "n", - "company": "c", - "blog": "b", - "location": "l", - "email": "e", - "hireable": true, - "public_repos": 1, - "followers": 1, - "following": 1, - "created_at": ` + referenceTimeStr + `, - "url": "u" - }, - "reactions": { - "total_count": 1, - "+1": 1, - "-1": 0, - "laugh": 0, - "confused": 0, - "heart": 0, - "hooray": 0, - "url": "u" - }, - "created_at": "2002-02-10T15:30:00Z", - "updated_at": "2002-02-10T15:30:00Z", - "url": "pullrequestcommentUrl", - "html_url": "pullrequestcommentHTMLUrl", - "pull_request_url": "pullrequestcommentPullRequestURL" + "id": 10, + "in_reply_to_id": 8, + "body": "Test comment", + "path": "file1.txt", + "diff_hunk": "@@ -16,33 +16,40 @@ fmt.Println()", + "pull_request_review_id": 42, + "position": 1, + "original_position": 4, + "commit_id": "ab", + "original_commit_id": "9c", + "user": { + "login": "ll", + "id": 123, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "url": "u" + }, + "reactions": { + "total_count": 1, + "+1": 1, + "-1": 0, + "laugh": 0, + "confused": 0, + "heart": 0, + "hooray": 0, + "url": "u" + }, + "created_at": "2002-02-10T15:30:00Z", + "updated_at": "2002-02-10T15:30:00Z", + "url": "pullrequestcommentUrl", + "html_url": "pullrequestcommentHTMLUrl", + "pull_request_url": "pullrequestcommentPullRequestURL" }` testJSONMarshal(t, u, want) From b45b1d2aff48d507eef40b60c4499695bfc47e02 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Wed, 3 Apr 2019 18:52:01 +0530 Subject: [PATCH 10/10] fixed formatting of code --- github/gists_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/gists_test.go b/github/gists_test.go index 43f98a4b271..2d79b8c5e8b 100644 --- a/github/gists_test.go +++ b/github/gists_test.go @@ -43,7 +43,7 @@ func TestGist_marshall(t *testing.T) { URL: String("u"), }, Files: map[GistFilename]GistFile{ - "gistfile.py": GistFile{ + "gistfile.py": { Size: Int(167), Filename: String("gistfile.py"), Language: String("Python"),