diff --git a/handler/gitlab.go b/handler/gitlab.go index 292d41c..d9391f3 100644 --- a/handler/gitlab.go +++ b/handler/gitlab.go @@ -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 } diff --git a/handler/gitlab_test.go b/handler/gitlab_test.go index d5adb2e..ef1d6a9 100644 --- a/handler/gitlab_test.go +++ b/handler/gitlab_test.go @@ -1,6 +1,7 @@ package handler_test import ( + "errors" "io/ioutil" "net/http" "net/http/httptest" @@ -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()) +}