From 318bbeff38c6b03798406c22caa5f31319a04e88 Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Fri, 16 Jul 2021 23:07:22 +0530 Subject: [PATCH 1/2] Resources Covered : - Metric - CommunityHealthFiles - CommunityHealthMetrics --- github/repos_community_health_test.go | 196 ++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index 2eb495aeaf7..46ccd1472b3 100644 --- a/github/repos_community_health_test.go +++ b/github/repos_community_health_test.go @@ -100,3 +100,199 @@ func TestRepositoriesService_GetCommunityHealthMetrics(t *testing.T) { return resp, err }) } + +func TestMetric_Marshal(t *testing.T) { + testJSONMarshal(t, &Metric{}, "{}") + + r := &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + } + + want := `{ + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }` + + testJSONMarshal(t, r, want) +} + +func TestCommunityHealthFiles_Marshal(t *testing.T) { + testJSONMarshal(t, &CommunityHealthFiles{}, "{}") + + r := &CommunityHealthFiles{ + CodeOfConduct: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + Contributing: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + IssueTemplate: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + PullRequestTemplate: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + License: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + Readme: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + } + + want := `{ + "code_of_conduct": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "contributing": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "issue_template": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "pull_request_template": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "license": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "readme": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + } + }` + + testJSONMarshal(t, r, want) +} + +func TestCommunityHealthMetrics_Marshal(t *testing.T) { + testJSONMarshal(t, &CommunityHealthMetrics{}, "{}") + + r := &CommunityHealthMetrics{ + HealthPercentage: Int(1), + Files: &CommunityHealthFiles{ + CodeOfConduct: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + Contributing: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + IssueTemplate: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + PullRequestTemplate: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + License: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + Readme: &Metric{ + Name: String("name"), + Key: String("key"), + URL: String("url"), + HTMLURL: String("hurl"), + }, + }, + UpdatedAt: &referenceTime, + } + + want := `{ + "health_percentage": 1, + "files": { + "code_of_conduct": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "contributing": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "issue_template": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "pull_request_template": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "license": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + }, + "readme": { + "name": "name", + "key": "key", + "url": "url", + "html_url": "hurl" + } + }, + "updated_at": "2006-01-02T15:04:05Z" + }` + + testJSONMarshal(t, r, want) +} From 62e7ba79b60575058373618e3f9687d863dc44a4 Mon Sep 17 00:00:00 2001 From: Sagar Sonwane <44731466+sagar23sj@users.noreply.github.com> Date: Fri, 16 Jul 2021 23:19:50 +0530 Subject: [PATCH 2/2] updated referenceTime in json message --- github/repos_community_health_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index 46ccd1472b3..24a62493c4e 100644 --- a/github/repos_community_health_test.go +++ b/github/repos_community_health_test.go @@ -291,7 +291,7 @@ func TestCommunityHealthMetrics_Marshal(t *testing.T) { "html_url": "hurl" } }, - "updated_at": "2006-01-02T15:04:05Z" + "updated_at": ` + referenceTimeStr + ` }` testJSONMarshal(t, r, want)