From 08502a492c16874ce6fed60d6ca58f357bd4181c Mon Sep 17 00:00:00 2001 From: Jehandad Kamal Date: Tue, 15 Jun 2021 11:47:50 +0500 Subject: [PATCH 1/2] fix(tests): update tests to be configured from ENV added two ENV Variables for configuring repository and owner on which the integration test is performed. --- github_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/github_test.go b/github_test.go index 9405735..55b3fa3 100644 --- a/github_test.go +++ b/github_test.go @@ -14,10 +14,32 @@ import ( ) const ( + // EnvRepoOwner is an environment var for the repository owner on which the github release test is performed + EnvRepoOwner = "TEST_REPO_OWNER" + // EnvRepoName is an environment var for the name of repository on which the github release test is performed + EnvRepoName = "TEST_REPO_NAME" +) + +var ( TestOwner = "ghtools" TestRepo = "github-api-test" ) +func TestMain(m *testing.M) { + owner := os.Getenv(EnvRepoOwner) + if owner != "" { + TestOwner = owner + } + + repo := os.Getenv(EnvRepoName) + if repo != "" { + TestRepo = repo + } + + code := m.Run() + os.Exit(code) +} + func testGithubClient(t *testing.T) GitHub { token := os.Getenv(EnvGitHubToken) client, err := NewGitHubClient(TestOwner, TestRepo, token, defaultBaseURL) From be0a17b82a1aa81d0d04c1c5a1f3dcbf50aaa761 Mon Sep 17 00:00:00 2001 From: Jehandad Kamal Date: Tue, 15 Jun 2021 11:50:34 +0500 Subject: [PATCH 2/2] update(readme): add steps for configuring tests --- README.md | 2 +- github_test.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d17a4f..4324d7b 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ $ go get -u github.com/tcnksm/ghr 2. Create a feature branch 3. Commit your changes 4. Rebase your local changes against the master branch -5. Run test suite with the `make test` command and confirm that it passes +5. Run test suite with the `make test` command and confirm that it passes using correct variables e.g. `GITHUB_TOKEN=$GITHUB_TOKEN TEST_REPO_OWNER=tcnksm TEST_REPO_NAME=ghr make test` 6. Run `gofmt -s -w .` 7. Create new Pull Request diff --git a/github_test.go b/github_test.go index 55b3fa3..9ff8e79 100644 --- a/github_test.go +++ b/github_test.go @@ -26,13 +26,11 @@ var ( ) func TestMain(m *testing.M) { - owner := os.Getenv(EnvRepoOwner) - if owner != "" { + if owner := os.Getenv(EnvRepoOwner); owner != "" { TestOwner = owner } - repo := os.Getenv(EnvRepoName) - if repo != "" { + if repo := os.Getenv(EnvRepoName); repo != "" { TestRepo = repo }