From 89ef2876ab1ff5ab1130bd36a3010a97a7c2e3f2 Mon Sep 17 00:00:00 2001 From: Edward Marshall Date: Wed, 30 Sep 2020 11:08:49 +0100 Subject: [PATCH] Re-instated dockerfile, removed legacy tests --- Dockerfile | 6 +-- test/github_exporter_test.go | 78 ------------------------------------ 2 files changed, 3 insertions(+), 81 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b79606c..3ffefb33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/test/github_exporter_test.go b/test/github_exporter_test.go index 0750d4d8..890fe7c0 100644 --- a/test/github_exporter_test.go +++ b/test/github_exporter_test.go @@ -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) @@ -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)