diff --git a/github/repos_community_health_test.go b/github/repos_community_health_test.go index 2eb495aeaf7..24a62493c4e 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": ` + referenceTimeStr + ` + }` + + testJSONMarshal(t, r, want) +}