Skip to content

Commit

Permalink
fix github workflow, add more tests to get 90%+ coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
imsky committed May 1, 2019
1 parent f13b994 commit 32bd704
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/main.workflow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workflow "github-fresh" {
workflow "Run github-fresh on every pull request update" {
on = "pull_request"
resolves = ["github-fresh"]
}
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit 32bd704

Please sign in to comment.