From 4c4381bc0dbf3842b4779969968878e7d5cad5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricco=20F=C3=B8rgaard?= Date: Mon, 10 Jun 2019 17:35:53 +0200 Subject: [PATCH 1/4] Add test for CheckRun marshalling --- github/checks_test.go | 184 ++++++++++++++++++++++++++++++++++++++++++ github/github_test.go | 2 +- 2 files changed, 185 insertions(+), 1 deletion(-) diff --git a/github/checks_test.go b/github/checks_test.go index 9e5bc1fcbd..7d5bd0d001 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -479,3 +479,187 @@ func TestChecksService_ReRequestCheckSuite(t *testing.T) { t.Errorf("Checks.ReRequestCheckSuite = %v, want %v", got, want) } } + +func Test_marshall(t *testing.T) { + testJSONMarshal(t, &CheckRun{}, "{}") + + now := time.Now() + ts := now.Format(time.RFC3339Nano) + + c := CheckRun{ + ID: Int64(1), + NodeID: String("n"), + HeadSHA: String("h"), + ExternalID: String("1"), + URL: String("u"), + HTMLURL: String("u"), + DetailsURL: String("u"), + Status: String("s"), + Conclusion: String("c"), + StartedAt: &Timestamp{Time: now}, + CompletedAt: &Timestamp{Time: now}, + Output: &CheckRunOutput{ + Annotations: []*CheckRunAnnotation{ + &CheckRunAnnotation{ + AnnotationLevel: String("a"), + BlobHRef: String("b"), + EndLine: Int(1), + Message: String("m"), + Path: String("p"), + RawDetails: String("r"), + StartLine: Int(1), + Title: String("t"), + }, + }, + AnnotationsCount: Int(1), + AnnotationsURL: String("a"), + Images: []*CheckRunImage{ + &CheckRunImage{ + Alt: String("a"), + ImageURL: String("i"), + Caption: String("c"), + }, + }, + Title: String("t"), + Summary: String("s"), + Text: String("t"), + }, + Name: String("n"), + CheckSuite: &CheckSuite{ + ID: Int64(1), + }, + App: &App{ + ID: Int64(1), + NodeID: String("n"), + Owner: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Name: String("n"), + Description: String("d"), + HTMLURL: String("h"), + ExternalURL: String("u"), + CreatedAt: &now, + UpdatedAt: &now, + }, + PullRequests: []*PullRequest{ + &PullRequest{ + URL: String("u"), + ID: Int64(1), + Number: Int(1), + Head: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("s"), + Name: String("n"), + }, + }, + Base: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + }, + }, + }, + } + w := fmt.Sprintf(`{ + "id": 1, + "node_id": "n", + "head_sha": "h", + "external_id": "1", + "url": "u", + "html_url": "u", + "details_url": "u", + "status": "s", + "conclusion": "c", + "started_at": "%s", + "completed_at": "%s", + "output": { + "title": "t", + "summary": "s", + "text": "t", + "annotations_count": 1, + "annotations_url": "a", + "annotations": [ + { + "path": "p", + "blob_href": "b", + "start_line": 1, + "end_line": 1, + "annotation_level": "a", + "message": "m", + "title": "t", + "raw_details": "r" + } + ], + "images": [ + { + "alt": "a", + "image_url": "i", + "caption": "c" + } + ] + }, + "name": "n", + "check_suite": { + "id": 1 + }, + "app": { + "id": 1, + "node_id": "n", + "owner": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "name": "n", + "description": "d", + "external_url": "u", + "html_url": "h", + "created_at": "%s", + "updated_at": "%s" + }, + "pull_requests": [ + { + "id": 1, + "number": 1, + "url": "u", + "head": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "s" + } + }, + "base": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "u" + } + } + } + ] + }`, ts, ts, ts, ts) + + testJSONMarshal(t, &c, w) +} diff --git a/github/github_test.go b/github/github_test.go index 4a2581b019..47f009cf50 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -155,7 +155,7 @@ func testJSONMarshal(t *testing.T, v interface{}, want string) { // now go the other direction and make sure things unmarshal as expected u := reflect.ValueOf(v).Interface() if err := json.Unmarshal([]byte(want), u); err != nil { - t.Errorf("Unable to unmarshal JSON for %v", want) + t.Errorf("Unable to unmarshal JSON for %v: %v", want, err) } if !reflect.DeepEqual(v, u) { From 486fbca70e4380a2a973623c72bd5e4821684696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricco=20F=C3=B8rgaard?= Date: Mon, 10 Jun 2019 18:28:40 +0200 Subject: [PATCH 2/4] Add tests for CheckSuite marshalling --- github/checks_test.go | 135 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/github/checks_test.go b/github/checks_test.go index 7d5bd0d001..36e150bff3 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -480,7 +480,7 @@ func TestChecksService_ReRequestCheckSuite(t *testing.T) { } } -func Test_marshall(t *testing.T) { +func Test_CheckRunMarshall(t *testing.T) { testJSONMarshal(t, &CheckRun{}, "{}") now := time.Now() @@ -663,3 +663,136 @@ func Test_marshall(t *testing.T) { testJSONMarshal(t, &c, w) } + +func Test_CheckSuiteMarshall(t *testing.T) { + testJSONMarshal(t, &CheckSuite{}, "{}") + + now := time.Now() + ts := now.Format(time.RFC3339Nano) + + c := CheckSuite{ + ID: Int64(1), + NodeID: String("n"), + HeadBranch: String("h"), + HeadSHA: String("h"), + URL: String("u"), + BeforeSHA: String("b"), + AfterSHA: String("a"), + Status: String("s"), + Conclusion: String("c"), + App: &App{ + ID: Int64(1), + NodeID: String("n"), + Owner: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Name: String("n"), + Description: String("d"), + HTMLURL: String("h"), + ExternalURL: String("u"), + CreatedAt: &now, + UpdatedAt: &now, + }, + Repository: &Repository{ + ID: Int64(1), + }, + PullRequests: []*PullRequest{ + &PullRequest{ + URL: String("u"), + ID: Int64(1), + Number: Int(1), + Head: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("s"), + Name: String("n"), + }, + }, + Base: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + }, + }, + }, + HeadCommit: &Commit{ + SHA: String("s"), + }, + } + + w := fmt.Sprintf(`{ + "id": 1, + "node_id": "n", + "head_branch": "h", + "head_sha": "h", + "url": "u", + "before": "b", + "after": "a", + "status": "s", + "conclusion": "c", + "app": { + "id": 1, + "node_id": "n", + "owner": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "name": "n", + "description": "d", + "external_url": "u", + "html_url": "h", + "created_at": "%s", + "updated_at": "%s" + }, + "repository": { + "id": 1 + }, + "pull_requests": [ + { + "id": 1, + "number": 1, + "url": "u", + "head": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "s" + } + }, + "base": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "u" + } + } + } + ], + "head_commit": { + "sha": "s" + } + }`, ts, ts) + + testJSONMarshal(t, &c, w) +} From 8f5c5f2f9c654f80097234e6cb30a8d7c29e473d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricco=20F=C3=B8rgaard?= Date: Mon, 10 Jun 2019 19:07:29 +0200 Subject: [PATCH 3/4] Format code --- github/checks_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/checks_test.go b/github/checks_test.go index 36e150bff3..8fd7d47bf4 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -500,7 +500,7 @@ func Test_CheckRunMarshall(t *testing.T) { CompletedAt: &Timestamp{Time: now}, Output: &CheckRunOutput{ Annotations: []*CheckRunAnnotation{ - &CheckRunAnnotation{ + { AnnotationLevel: String("a"), BlobHRef: String("b"), EndLine: Int(1), @@ -514,7 +514,7 @@ func Test_CheckRunMarshall(t *testing.T) { AnnotationsCount: Int(1), AnnotationsURL: String("a"), Images: []*CheckRunImage{ - &CheckRunImage{ + { Alt: String("a"), ImageURL: String("i"), Caption: String("c"), @@ -548,7 +548,7 @@ func Test_CheckRunMarshall(t *testing.T) { UpdatedAt: &now, }, PullRequests: []*PullRequest{ - &PullRequest{ + { URL: String("u"), ID: Int64(1), Number: Int(1), @@ -703,7 +703,7 @@ func Test_CheckSuiteMarshall(t *testing.T) { ID: Int64(1), }, PullRequests: []*PullRequest{ - &PullRequest{ + { URL: String("u"), ID: Int64(1), Number: Int(1), From 0ba41c217b199b888113c525fd0fc9a0227c49f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricco=20F=C3=B8rgaard?= Date: Mon, 10 Jun 2019 22:45:12 +0200 Subject: [PATCH 4/4] Fix typo --- github/checks_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/checks_test.go b/github/checks_test.go index 8fd7d47bf4..214c9f0272 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -480,7 +480,7 @@ func TestChecksService_ReRequestCheckSuite(t *testing.T) { } } -func Test_CheckRunMarshall(t *testing.T) { +func Test_CheckRunMarshal(t *testing.T) { testJSONMarshal(t, &CheckRun{}, "{}") now := time.Now() @@ -664,7 +664,7 @@ func Test_CheckRunMarshall(t *testing.T) { testJSONMarshal(t, &c, w) } -func Test_CheckSuiteMarshall(t *testing.T) { +func Test_CheckSuiteMarshal(t *testing.T) { testJSONMarshal(t, &CheckSuite{}, "{}") now := time.Now()