Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions github/repos_community_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}