Skip to content

Commit

Permalink
gitlab.go: 100% code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
  • Loading branch information
malukenho committed Jul 7, 2022
1 parent 57e3e97 commit fb80921
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions handler/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func (g *Gitlab) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
return
}

err = g.provider.NotifyMergeRequestCreated(mr)
if err != nil {
if err = g.provider.NotifyMergeRequestCreated(mr); err != nil {
return err
}

Expand Down
28 changes: 28 additions & 0 deletions handler/gitlab_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler_test

import (
"errors"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -163,3 +164,30 @@ func TestPostOnSlackWithMergeRequestRejected(t *testing.T) {

assert.Equal(t, "We cannot handle rejected event action", recorder.Body.String())
}

func TestPostOnSlackWithReactToMessageFailure(t *testing.T) {
dat, err := ioutil.ReadFile("../payload/merge_request-rejected.json")
assert.Nil(t, err)

recorder := httptest.NewRecorder()
request := httptest.NewRequest(
http.MethodPost,
"http://some-url.com",
strings.NewReader(string(dat)),
)

provider := &SpyProvider{
NotifyMergeRequestCreatedFunc: func(mergeRequest model.MergeRequestInfo) (err error) {
assert.FailNow(t, "Code should not reach this method")

return
},
ReactToMessageFunc: func(mergeRequest model.MergeRequestInfo, reactionRule model.ReactionRule) (err error) {
return errors.New("Error from ReactToMessage")
},
}

handler.NewGitlab(provider).ServeHTTP(recorder, request)

assert.Equal(t, "We cannot handle rejected event action", recorder.Body.String())
}

0 comments on commit fb80921

Please sign in to comment.