Skip to content

Commit 5b1231b

Browse files
authored
Merge pull request #2 from iamrare/fix-test
fix test
2 parents 560314d + 982e943 commit 5b1231b

File tree

3 files changed

+1002
-3
lines changed

3 files changed

+1002
-3
lines changed

test/github_exporter_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ func TestGithubExporter(t *testing.T) {
3333
githubRepos(),
3434
githubRateLimit(),
3535
githubReleases(),
36+
githubPulls(),
3637
).
3738
Get("/metrics").
3839
Expect(t).
3940
Assert(bodyContains(`github_rate_limit 60`)).
4041
Assert(bodyContains(`github_rate_remaining 60`)).
4142
Assert(bodyContains(`github_rate_reset 1.566853865e+09`)).
4243
Assert(bodyContains(`github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 10`)).
44+
Assert(bodyContains(`github_repo_pull_request_count 3`)).
4345
Assert(bodyContains(`github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 2`)).
4446
Assert(bodyContains(`github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 946`)).
4547
Assert(bodyContains(`github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 120`)).
@@ -105,6 +107,17 @@ func githubReleases() *apitest.Mock {
105107
End()
106108
}
107109

110+
func githubPulls() *apitest.Mock {
111+
return apitest.NewMock().
112+
Get("https://api.github.com/repos/myOrg/myRepo/pulls").
113+
Header("Authorization", "token 12345").
114+
RespondWith().
115+
Times(2).
116+
Body(readFile("testdata/pulls_response.json")).
117+
Status(http.StatusOK).
118+
End()
119+
}
120+
108121
func readFile(path string) string {
109122
bytes, err := ioutil.ReadFile(path)
110123
if err != nil {

test/testdata/my_repo_response.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"mirror_url": null,
8686
"archived": false,
8787
"disabled": false,
88-
"open_issues_count": 2,
88+
"open_issues_count": 5,
8989
"license": {
9090
"key": "mit",
9191
"name": "MIT License",
@@ -94,9 +94,9 @@
9494
"node_id": "MDc6TGljZW5zZTEz"
9595
},
9696
"forks": 10,
97-
"open_issues": 2,
97+
"open_issues": 5,
9898
"watchers": 120,
9999
"default_branch": "master",
100100
"network_count": 10,
101101
"subscribers_count": 5
102-
}
102+
}

0 commit comments

Comments
 (0)