Skip to content

Commit

Permalink
Re-instated dockerfile, removed legacy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rucknar committed Sep 30, 2020
1 parent f6eabc9 commit 89ef287
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 81 deletions.
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

0 comments on commit 89ef287

Please sign in to comment.