Fix MR Selection, Go Code Refactor (#358)
refactor: Refactors the Go codebase into a more modular and idiomatic approach fix: require selection of specific MR when there are multiple targets for a given source branch feat: Allows for the passing of Gitlab's filter options when choosing an MR, improves MR selection feat: API to choose an MR from a list based on the provided username's involvement as an assignee/reviewer/author This is a #MINOR release
This commit is contained in:
committed by
GitHub
parent
6500ef1f2c
commit
ea2b2b2f5c
49
cmd/app/info_test.go
Normal file
49
cmd/app/info_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
type fakeMergeRequestGetter struct {
|
||||
testBase
|
||||
}
|
||||
|
||||
func (f fakeMergeRequestGetter) GetMergeRequest(pid interface{}, mergeRequest int, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error) {
|
||||
resp, err := f.handleGitlabError()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return &gitlab.MergeRequest{}, resp, err
|
||||
}
|
||||
|
||||
func TestInfoHandler(t *testing.T) {
|
||||
t.Run("Returns normal information", func(t *testing.T) {
|
||||
request := makeRequest(t, http.MethodGet, "/mr/info", nil)
|
||||
svc := infoService{testProjectData, fakeMergeRequestGetter{}}
|
||||
data := getSuccessData(t, svc, request)
|
||||
assert(t, data.Message, "Merge requests retrieved")
|
||||
assert(t, data.Status, http.StatusOK)
|
||||
})
|
||||
t.Run("Disallows non-GET methods", func(t *testing.T) {
|
||||
request := makeRequest(t, http.MethodPost, "/mr/info", nil)
|
||||
svc := infoService{testProjectData, fakeMergeRequestGetter{}}
|
||||
data := getFailData(t, svc, request)
|
||||
checkBadMethod(t, data, http.MethodGet)
|
||||
})
|
||||
t.Run("Handles errors from Gitlab client", func(t *testing.T) {
|
||||
request := makeRequest(t, http.MethodGet, "/mr/info", nil)
|
||||
svc := infoService{testProjectData, fakeMergeRequestGetter{testBase{errFromGitlab: true}}}
|
||||
data := getFailData(t, svc, request)
|
||||
checkErrorFromGitlab(t, data, "Could not get project info")
|
||||
})
|
||||
t.Run("Handles non-200s from Gitlab client", func(t *testing.T) {
|
||||
request := makeRequest(t, http.MethodGet, "/mr/info", nil)
|
||||
svc := infoService{testProjectData, fakeMergeRequestGetter{testBase{status: http.StatusSeeOther}}}
|
||||
data := getFailData(t, svc, request)
|
||||
checkNon200(t, data, "Could not get project info", "/mr/info")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user