Skip to content

Commit

Permalink
Add Headers testing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranza committed Sep 23, 2018
1 parent 2261201 commit 61c3bd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 9 additions & 11 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ func TestParsingPayloads(t *testing.T) {
}
}

// func TestInvalidPayloadErrs(t *testing.T) {
// a := assert.New(t)
func TestHeadersMatcher(t *testing.T) {
a := assert.New(t)
p := github.NewParser(".*")

// b, err := ioutil.ReadFile("fixtures/gitlab-push-event.json")
// a.Nil(err, "could not read fixture file")
// a.NotNilf(b, "content should not be nil")

// parser := gitlab.Parser{}
// mr, err := parser.Parse(b)
// a.Errorf(err, "json payload is not a merge request but a push")
// a.Equalf(gitlab.MergeRequest{}, mr, "merge request should be empty")
// }
a.Equal(false, p.MatchHeaders(map[string][]string{}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Gitlab-Event": {"pull_request"}}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Gitlab-Event": {"Merge Request Hook"}}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Github-Event": {"Merge Request Hook"}}))
a.Equal(true, p.MatchHeaders(map[string][]string{"X-Github-Event": {"pull_request"}}))
}
11 changes: 11 additions & 0 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ func TestInvalidPayloadErrs(t *testing.T) {
a.Errorf(err, "json payload is not a merge request but a push")
a.Equalf(gitlab.MergeRequest{}, mr, "merge request should be empty")
}

func TestHeadersMatcher(t *testing.T) {
a := assert.New(t)
p := gitlab.NewParser(".*")

a.Equal(false, p.MatchHeaders(map[string][]string{}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Github-Event": {"Merge Request Hook"}}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Github-Event": {"pull_request"}}))
a.Equal(false, p.MatchHeaders(map[string][]string{"X-Gitlab-Event": {"pull_request"}}))
a.Equal(true, p.MatchHeaders(map[string][]string{"X-Gitlab-Event": {"Merge Request Hook"}}))
}

0 comments on commit 61c3bd8

Please sign in to comment.