From 32bd7046046b2b3276657b2b8ebd9e97dd1c0d4c Mon Sep 17 00:00:00 2001 From: Ivan Malopinsky Date: Wed, 1 May 2019 10:45:00 -0400 Subject: [PATCH] fix github workflow, add more tests to get 90%+ coverage --- .github/main.workflow | 2 +- main.go | 7 ++++--- main_test.go | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/main.workflow b/.github/main.workflow index 265b14b..5b3f807 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -1,4 +1,4 @@ -workflow "github-fresh" { +workflow "Run github-fresh on every pull request update" { on = "pull_request" resolves = ["github-fresh"] } diff --git a/main.go b/main.go index b688d11..483b819 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( // todo: docs // todo: GitHub action +// todo: fix blank build vars when using go build // todo: add minimum age of pull request // todo: close old pull requests @@ -74,9 +75,9 @@ func (ex *Executor) makeRequest(method string, url string) (res *http.Response, return nil, err } req.Header.Add("Authorization", "token "+ex.token) - res, err = ex.client.Do(req) - if err != nil { - return nil, err + res, _ = ex.client.Do(req) + if res.StatusCode >= 400 { + return res, errors.New(res.Status) } return res, nil } diff --git a/main_test.go b/main_test.go index 6fba2ff..9b21d27 100644 --- a/main_test.go +++ b/main_test.go @@ -58,6 +58,27 @@ func TestGetDays(t *testing.T) { } } +func TestGetDry(t *testing.T) { + dry := getDry("true") + + if dry != true { + t.Errorf("Expected parsed dry flag value to equal true") + } +} + +func TestDeleteBranches(t *testing.T) { + ex := NewExecutor("token", false) + n, err := ex.deleteBranches("user", "repo", []string{"somebranch"}) + + if n != 0 { + t.Errorf("Expected deleted branches to equal 0 due to error") + } + + if err == nil { + t.Errorf("Expected error due to misconfigured executor") + } +} + func TestDryRun(t *testing.T) { ex := NewExecutor("token", true) db, _ := ex.deleteBranches("user", "repo", []string{"branch"})