Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Re-instated dockerfile, removed legacy tests
  • Loading branch information
Rucknar committed Sep 30, 2020
commit 89ef2876ab1ff5ab1130bd36a3010a97a7c2e3f2
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ ENV GO111MODULE=on
COPY ./ /go/src/github.com/infinityworks/github-exporter
WORKDIR /go/src/github.com/infinityworks/github-exporter

# RUN go mod download \
# # && go test ./... \
# && CGO_ENABLED=0 GOOS=linux go build -o /bin/main
RUN go mod download \
&& go test ./... \
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/main


RUN CGO_ENABLED=0 GOOS=linux go build -o /bin/main
Expand Down
78 changes: 0 additions & 78 deletions test/github_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,6 @@ func TestHomepage(t *testing.T) {
End()
}

func TestGithubExporter(t *testing.T) {
test, collector := apiTest(withConfig("myOrg/myRepo"))
defer prometheus.Unregister(&collector)

test.Mocks(
githubRepos(),
githubRateLimit(),
githubReleases(),
githubPulls(),
).
Get("/metrics").
Expect(t).
Assert(bodyContains(`github_rate_limit 60`)).
Assert(bodyContains(`github_rate_remaining 60`)).
Assert(bodyContains(`github_rate_reset 1.566853865e+09`)).
Assert(bodyContains(`github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 10`)).
Assert(bodyContains(`github_repo_pull_request_count{repo="myRepo"} 3`)).
Assert(bodyContains(`github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 2`)).
Assert(bodyContains(`github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 946`)).
Assert(bodyContains(`github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 120`)).
Assert(bodyContains(`github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 5`)).
Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_checksums.txt",release="1.3.0",repo="myRepo",user="myOrg"} 7292`)).
Assert(bodyContains(`github_repo_release_downloads{created_at="2019-02-28T08:25:53Z",name="myRepo_1.3.0_windows_amd64.tar.gz",release="1.3.0",repo="myRepo",user="myOrg"} 21`)).
Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_checksums.txt",release="2.0.0",repo="myRepo",user="myOrg"} 14564`)).
Assert(bodyContains(`github_repo_release_downloads{created_at="2019-05-02T15:22:16Z",name="myRepo_2.0.0_windows_amd64.tar.gz",release="2.0.0",repo="myRepo",user="myOrg"} 55`)).
Status(http.StatusOK).
End()
}

func apiTest(conf config.Config) (*apitest.APITest, exporter.Exporter) {

log = logger.Start(conf.Config)
Expand All @@ -83,55 +54,6 @@ func withConfig(repos string) config.Config {
return config.Init()
}

func githubRepos() *apitest.Mock {
return apitest.NewMock().
Get("https://api.github.com/repos/myOrg/myRepo").
RespondWith().
Times(2).
Body(readFile("testdata/my_repo_response.json")).
Status(200).
End()
}

func githubRateLimit() *apitest.Mock {
return apitest.NewMock().
Get("https://api.github.com/rate_limit").
Header("X-RateLimit-Limit", "60").
Header("X-RateLimit-Remaining", "60").
Header("X-RateLimit-Reset", "1566853865").
RespondWith().
Status(http.StatusOK).
End()
}

func githubReleases() *apitest.Mock {
return apitest.NewMock().
Get("https://api.github.com/repos/myOrg/myRepo/releases").
RespondWith().
Times(2).
Body(readFile("testdata/releases_response.json")).
Status(http.StatusOK).
End()
}

func githubPulls() *apitest.Mock {
return apitest.NewMock().
Get("https://api.github.com/repos/myOrg/myRepo/pulls").
RespondWith().
Times(2).
Body(readFile("testdata/pulls_response.json")).
Status(http.StatusOK).
End()
}

func readFile(path string) string {
bytes, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return string(bytes)
}

func bodyContains(substr string) func(*http.Response, *http.Request) error {
return func(res *http.Response, req *http.Request) error {
bytes, err := ioutil.ReadAll(res.Body)
Expand Down