mirror of https://gitlab.com/gitlab-org/cli.git
refactor(test): use http constants in tests
This commit is contained in:
parent
b971cbeee7
commit
c75eef927b
|
@ -39,7 +39,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "graphql",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "graphql",
|
||||
RequestInputFile: "",
|
||||
|
@ -57,7 +57,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "projects/octocat%2FSpoon-Knife -XDELETE",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "DELETE",
|
||||
RequestMethod: http.MethodDelete,
|
||||
RequestMethodPassed: true,
|
||||
RequestPath: "projects/octocat%2FSpoon-Knife",
|
||||
RequestInputFile: "",
|
||||
|
@ -75,7 +75,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "graphql -f query=QUERY -F body=@file.txt",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "graphql",
|
||||
RequestInputFile: "",
|
||||
|
@ -93,7 +93,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "user -H 'accept: text/plain' -i",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "user",
|
||||
RequestInputFile: "",
|
||||
|
@ -111,7 +111,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "projects/OWNER%2FREPO/issues --paginate",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "projects/OWNER%2FREPO/issues",
|
||||
RequestInputFile: "",
|
||||
|
@ -129,7 +129,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "projects/OWNER%2FREPO/issues --silent",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "projects/OWNER%2FREPO/issues",
|
||||
RequestInputFile: "",
|
||||
|
@ -152,7 +152,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "-XPOST graphql --paginate",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "POST",
|
||||
RequestMethod: http.MethodPost,
|
||||
RequestMethodPassed: true,
|
||||
RequestPath: "graphql",
|
||||
RequestInputFile: "",
|
||||
|
@ -175,7 +175,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "user --input myfile",
|
||||
wants: ApiOptions{
|
||||
Hostname: "",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "user",
|
||||
RequestInputFile: "myfile",
|
||||
|
@ -198,7 +198,7 @@ func Test_NewCmdApi(t *testing.T) {
|
|||
cli: "graphql --hostname tom.petty",
|
||||
wants: ApiOptions{
|
||||
Hostname: "tom.petty",
|
||||
RequestMethod: "GET",
|
||||
RequestMethod: http.MethodGet,
|
||||
RequestMethodPassed: false,
|
||||
RequestPath: "graphql",
|
||||
RequestInputFile: "",
|
||||
|
@ -255,7 +255,7 @@ func Test_apiRun(t *testing.T) {
|
|||
{
|
||||
name: "success",
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`bam!`)),
|
||||
},
|
||||
err: nil,
|
||||
|
@ -270,7 +270,7 @@ func Test_apiRun(t *testing.T) {
|
|||
httpResponse: &http.Response{
|
||||
Proto: "HTTP/1.1",
|
||||
Status: "200 Okey-dokey",
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`body`)),
|
||||
Header: http.Header{"Content-Type": []string{"text/plain"}},
|
||||
},
|
||||
|
@ -281,7 +281,7 @@ func Test_apiRun(t *testing.T) {
|
|||
{
|
||||
name: "success 204",
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 204,
|
||||
StatusCode: http.StatusNoContent,
|
||||
Body: nil,
|
||||
},
|
||||
err: nil,
|
||||
|
@ -291,7 +291,7 @@ func Test_apiRun(t *testing.T) {
|
|||
{
|
||||
name: "REST error",
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 400,
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)),
|
||||
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
|
||||
},
|
||||
|
@ -302,7 +302,7 @@ func Test_apiRun(t *testing.T) {
|
|||
{
|
||||
name: "REST string errors",
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 400,
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"errors": ["ALSO", "FINE"]}`)),
|
||||
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
|
||||
},
|
||||
|
@ -316,7 +316,7 @@ func Test_apiRun(t *testing.T) {
|
|||
RequestPath: "graphql",
|
||||
},
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"errors": [{"message":"AGAIN"}, {"message":"FINE"}]}`)),
|
||||
Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}},
|
||||
},
|
||||
|
@ -327,7 +327,7 @@ func Test_apiRun(t *testing.T) {
|
|||
{
|
||||
name: "failure",
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 502,
|
||||
StatusCode: http.StatusBadGateway,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`gateway timeout`)),
|
||||
},
|
||||
err: cmdutils.SilentError,
|
||||
|
@ -340,7 +340,7 @@ func Test_apiRun(t *testing.T) {
|
|||
Silent: true,
|
||||
},
|
||||
httpResponse: &http.Response{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`body`)),
|
||||
},
|
||||
err: nil,
|
||||
|
@ -356,7 +356,7 @@ func Test_apiRun(t *testing.T) {
|
|||
httpResponse: &http.Response{
|
||||
Proto: "HTTP/1.1",
|
||||
Status: "200 Okey-dokey",
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`body`)),
|
||||
Header: http.Header{"Content-Type": []string{"text/plain"}},
|
||||
},
|
||||
|
@ -406,21 +406,21 @@ func Test_apiRun_paginationREST(t *testing.T) {
|
|||
requestCount := 0
|
||||
responses := []*http.Response{
|
||||
{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"page":1}`)),
|
||||
Header: http.Header{
|
||||
"Link": []string{`<https://gitlab.com/api/v4/projects/1227/issues?page=2>; rel="next", <https://gitlab.com/api/v4/projects/1227/issues?page=3>; rel="last"`},
|
||||
},
|
||||
},
|
||||
{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"page":2}`)),
|
||||
Header: http.Header{
|
||||
"Link": []string{`<https://gitlab.com/api/v4/projects/1227/issues?page=3>; rel="next", <https://gitlab.com/api/v4/projects/1227/issues?page=3>; rel="last"`},
|
||||
},
|
||||
},
|
||||
{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"page":3}`)),
|
||||
Header: http.Header{},
|
||||
},
|
||||
|
@ -464,7 +464,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
|
|||
requestCount := 0
|
||||
responses := []*http.Response{
|
||||
{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{`application/json`}},
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{
|
||||
"data": {
|
||||
|
@ -477,7 +477,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
|
|||
}`)),
|
||||
},
|
||||
{
|
||||
StatusCode: 200,
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{`application/json`}},
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{
|
||||
"data": {
|
||||
|
@ -508,7 +508,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) {
|
|||
return a.Lab(), nil
|
||||
},
|
||||
|
||||
RequestMethod: "POST",
|
||||
RequestMethod: http.MethodPost,
|
||||
RequestPath: "graphql",
|
||||
Paginate: true,
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ func Test_apiRun_inputFile(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ios, stdin, _, _ := iostreams.Test()
|
||||
resp := &http.Response{StatusCode: 204}
|
||||
resp := &http.Response{StatusCode: http.StatusNoContent}
|
||||
|
||||
inputFile := tt.inputFile
|
||||
if tt.inputFile == "-" {
|
||||
|
@ -611,7 +611,7 @@ func Test_apiRun_inputFile(t *testing.T) {
|
|||
t.Errorf("got error %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "POST", resp.Request.Method)
|
||||
assert.Equal(t, http.MethodPost, resp.Request.Method)
|
||||
assert.Equal(t, "/api/v4/hello?a=b&c=d", resp.Request.URL.RequestURI())
|
||||
assert.Equal(t, tt.contentLength, resp.Request.ContentLength)
|
||||
assert.Equal(t, "", resp.Request.Header.Get("Content-Type"))
|
||||
|
|
|
@ -140,7 +140,7 @@ hosts:
|
|||
name: "simple GET",
|
||||
args: args{
|
||||
host: "gitlab.com",
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
p: "projects/gitlab-com%2Fwww-gitlab-com",
|
||||
params: nil,
|
||||
headers: []string{},
|
||||
|
@ -148,7 +148,7 @@ hosts:
|
|||
wantErr: false,
|
||||
isGraphQL: false,
|
||||
want: expects{
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com",
|
||||
body: "",
|
||||
headers: fmt.Sprintf("Private-Token: OTOKEN\r\nUser-Agent: %s\r\n", versionString),
|
||||
|
@ -158,7 +158,7 @@ hosts:
|
|||
name: "GET with leading slash",
|
||||
args: args{
|
||||
host: "gitlab.com",
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
p: "/projects/gitlab-com%2Fwww-gitlab-com",
|
||||
params: nil,
|
||||
headers: []string{},
|
||||
|
@ -166,7 +166,7 @@ hosts:
|
|||
wantErr: false,
|
||||
isGraphQL: false,
|
||||
want: expects{
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com",
|
||||
body: "",
|
||||
headers: fmt.Sprintf("Private-Token: OTOKEN\r\nUser-Agent: %s\r\n", versionString),
|
||||
|
@ -176,7 +176,7 @@ hosts:
|
|||
name: "GET with params",
|
||||
args: args{
|
||||
host: "gitlab.com",
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
p: "projects/gitlab-com%2Fwww-gitlab-com",
|
||||
params: map[string]interface{}{
|
||||
"a": "b",
|
||||
|
@ -186,7 +186,7 @@ hosts:
|
|||
wantErr: false,
|
||||
isGraphQL: false,
|
||||
want: expects{
|
||||
method: "GET",
|
||||
method: http.MethodGet,
|
||||
u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com?a=b",
|
||||
body: "",
|
||||
headers: fmt.Sprintf("Private-Token: OTOKEN\r\nUser-Agent: %s\r\n", versionString),
|
||||
|
@ -196,7 +196,7 @@ hosts:
|
|||
name: "POST GraphQL",
|
||||
args: args{
|
||||
host: "gitlab.com",
|
||||
method: "POST",
|
||||
method: http.MethodPost,
|
||||
p: "graphql",
|
||||
params: map[string]interface{}{
|
||||
"a": []byte("b"),
|
||||
|
@ -206,7 +206,7 @@ hosts:
|
|||
wantErr: false,
|
||||
isGraphQL: true,
|
||||
want: expects{
|
||||
method: "POST",
|
||||
method: http.MethodPost,
|
||||
u: "https://gitlab.com/api/graphql/",
|
||||
body: `{"variables":{"a":"b"}}`,
|
||||
headers: fmt.Sprintf("Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: %s\r\n", versionString),
|
||||
|
@ -216,7 +216,7 @@ hosts:
|
|||
name: "POST with body and type",
|
||||
args: args{
|
||||
host: "gitlab.com",
|
||||
method: "POST",
|
||||
method: http.MethodPost,
|
||||
p: "projects",
|
||||
params: bytes.NewBufferString("CUSTOM"),
|
||||
headers: []string{
|
||||
|
@ -227,7 +227,7 @@ hosts:
|
|||
wantErr: false,
|
||||
isGraphQL: false,
|
||||
want: expects{
|
||||
method: "POST",
|
||||
method: http.MethodPost,
|
||||
u: "https://gitlab.com/api/v4/projects",
|
||||
body: `CUSTOM`,
|
||||
headers: fmt.Sprintf("Accept: application/json\r\nContent-Type: text/plain\r\nPrivate-Token: OTOKEN\r\nUser-Agent: %s\r\n", versionString),
|
||||
|
|
|
@ -146,12 +146,12 @@ hosts:
|
|||
}
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "https://gitlab.alpinelinux.org/api/v4/user", httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "https://gitlab.alpinelinux.org/api/v4/user", httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"username": "john_smith"
|
||||
}
|
||||
`))
|
||||
fakeHTTP.RegisterResponder("GET", "https://gitlab.foo.bar/api/v4/user", httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "https://gitlab.foo.bar/api/v4/user", httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"username": "john_doe"
|
||||
}
|
||||
|
@ -200,19 +200,19 @@ hosts:
|
|||
|
||||
cfgFile := config.ConfigFile()
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "https://gitlab.alpinelinux.org/api/v4/user", httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "https://gitlab.alpinelinux.org/api/v4/user", httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"username": "john_smith"
|
||||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "https://another.host/api/v4/user?u=1", httpmock.NewStringResponse(401, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "https://another.host/api/v4/user?u=1", httpmock.NewStringResponse(http.StatusUnauthorized, `
|
||||
{
|
||||
"message": "invalid token"
|
||||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "https://gl.io/api/v4/user?u=1", httpmock.NewStringResponse(401, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "https://gl.io/api/v4/user?u=1", httpmock.NewStringResponse(http.StatusUnauthorized, `
|
||||
{
|
||||
"message": "no token provided"
|
||||
}
|
||||
|
|
|
@ -184,8 +184,8 @@ func Test_NewCmdRun(t *testing.T) {
|
|||
tempPath, tempFileName := createZipFile(t, tt.filename)
|
||||
// defer os.Remove(tempFileName)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/jobs/artifacts/main/download?job=secret_detection`,
|
||||
httpmock.NewFileResponse(200, tempFileName))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/jobs/artifacts/main/download?job=secret_detection`,
|
||||
httpmock.NewFileResponse(http.StatusOK, tempFileName))
|
||||
|
||||
cmd := NewCmdRun(factory)
|
||||
|
||||
|
@ -228,8 +228,8 @@ func Test_NewCmdRun(t *testing.T) {
|
|||
tempPath, tempFileName := createSymlinkZip(t)
|
||||
defer os.Remove(tempFileName)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/jobs/artifacts/main/download?job=secret_detection`,
|
||||
httpmock.NewFileResponse(200, tempFileName))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/jobs/artifacts/main/download?job=secret_detection`,
|
||||
httpmock.NewFileResponse(http.StatusOK, tempFileName))
|
||||
|
||||
cmd := NewCmdRun(factory)
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ func TestCiDelete(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("DELETE", "/api/v4/projects/OWNER/REPO/pipelines/11111111",
|
||||
httpmock.NewStringResponse(204, ""),
|
||||
fakeHTTP.RegisterResponder(http.MethodDelete, "/api/v4/projects/OWNER/REPO/pipelines/11111111",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, ""),
|
||||
)
|
||||
|
||||
pipelineId := "11111111"
|
||||
|
@ -52,11 +52,11 @@ func TestCiDeleteMultiple(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("DELETE", "/api/v4/projects/OWNER/REPO/pipelines/11111111",
|
||||
httpmock.NewStringResponse(204, ""),
|
||||
fakeHTTP.RegisterResponder(http.MethodDelete, "/api/v4/projects/OWNER/REPO/pipelines/11111111",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, ""),
|
||||
)
|
||||
fakeHTTP.RegisterResponder("DELETE", "/api/v4/projects/OWNER/REPO/pipelines/22222222",
|
||||
httpmock.NewStringResponse(204, ""),
|
||||
fakeHTTP.RegisterResponder(http.MethodDelete, "/api/v4/projects/OWNER/REPO/pipelines/22222222",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, ""),
|
||||
)
|
||||
|
||||
pipelineId := "11111111,22222222"
|
||||
|
|
|
@ -34,8 +34,8 @@ func TestCiList(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/api/v4/projects/OWNER/REPO/pipelines",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/api/v4/projects/OWNER/REPO/pipelines",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
|
|
|
@ -30,8 +30,8 @@ func TestCiRetry(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
// test will fail with unmatched HTTP stub if this POST is not performed
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/jobs/1122/retry",
|
||||
httpmock.NewStringResponse(201, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/jobs/1122/retry",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"id": 1123,
|
||||
"status": "pending",
|
||||
|
|
|
@ -86,8 +86,8 @@ func TestIssueList_tty(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/issuableList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/issuableList.json"))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "", nil, "")
|
||||
if err != nil {
|
||||
|
@ -113,8 +113,8 @@ func TestIssueList_ids(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/issuableList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/issuableList.json"))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "-F ids", nil, "")
|
||||
if err != nil {
|
||||
|
@ -131,8 +131,8 @@ func TestIssueList_urls(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/issuableList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/issuableList.json"))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "-F urls", nil, "")
|
||||
if err != nil {
|
||||
|
@ -154,8 +154,8 @@ func TestIssueList_tty_withFlags(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewStringResponse(200, `[]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[]`))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "--opened -P1 -p100 --confidential -a someuser -l bug -m1", nil, "")
|
||||
if err != nil {
|
||||
|
@ -172,8 +172,8 @@ func TestIssueList_tty_withFlags(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/groups/GROUP/issues",
|
||||
httpmock.NewStringResponse(200, `[]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/groups/GROUP/issues",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[]`))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "--group GROUP", nil, "")
|
||||
if err != nil {
|
||||
|
@ -192,8 +192,8 @@ func TestIssueList_tty_withIssueType(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/incidentList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/incidentList.json"))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "--issue-type=incident", nil, "")
|
||||
if err != nil {
|
||||
|
@ -216,8 +216,8 @@ func TestIssueList_tty_withIssueType(t *testing.T) {
|
|||
func TestIncidentList_tty_withIssueType(t *testing.T) {
|
||||
fakeHTTP := httpmock.New()
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/incidentList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/incidentList.json"))
|
||||
|
||||
output, err := runCommand("incident", fakeHTTP, true, "--issue-type=incident", nil, "")
|
||||
if err == nil {
|
||||
|
@ -233,11 +233,11 @@ func TestIssueList_tty_mine(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewStringResponse(200, `[]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[]`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/user",
|
||||
httpmock.NewStringResponse(200, `{"username": "john_smith"}`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/user",
|
||||
httpmock.NewStringResponse(http.StatusOK, `{"username": "john_smith"}`))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "--mine -A", nil, "")
|
||||
if err != nil {
|
||||
|
@ -254,8 +254,8 @@ func TestIssueList_tty_mine(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/user",
|
||||
httpmock.NewStringResponse(404, `{message: 404 Not found}`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/user",
|
||||
httpmock.NewStringResponse(http.StatusNotFound, `{message: 404 Not found}`))
|
||||
|
||||
output, err := runCommand("issue", fakeHTTP, true, "--mine -A", nil, "")
|
||||
assert.NotNil(t, err)
|
||||
|
@ -313,8 +313,8 @@ func TestIssueList_hyperlinks(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/issuableList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/issuableList.json"))
|
||||
|
||||
doHyperlinks := "never"
|
||||
if test.forceHyperlinksEnv == "1" {
|
||||
|
|
|
@ -30,8 +30,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("--message flag specified", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(201, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"id": 301,
|
||||
"created_at": "2013-10-02T08:57:14Z",
|
||||
|
@ -43,8 +43,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -63,8 +63,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("issue not found", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/122",
|
||||
httpmock.NewStringResponse(404, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues/122",
|
||||
httpmock.NewStringResponse(http.StatusNotFound, `
|
||||
{
|
||||
"message" : "issue not found"
|
||||
}
|
||||
|
@ -82,15 +82,15 @@ func Test_NewCmdNote_error(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("note could not be created", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(401, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusUnauthorized, `
|
||||
{
|
||||
"message" : "Unauthorized"
|
||||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -110,8 +110,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("message provided", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(201, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/issues/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"id": 301,
|
||||
"created_at": "2013-10-02T08:57:14Z",
|
||||
|
@ -123,8 +123,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -146,8 +146,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("message is empty", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/issues/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
|
|
@ -34,8 +34,8 @@ func TestLabelList(t *testing.T) {
|
|||
fakeHTTP := &httpmock.Mocker{}
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/api/v4/projects/OWNER/REPO/labels",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/api/v4/projects/OWNER/REPO/labels",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{
|
||||
"id":1,
|
||||
|
|
|
@ -57,8 +57,8 @@ func TestMrApprove(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(200, `{
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -66,8 +66,8 @@ func TestMrApprove(t *testing.T) {
|
|||
"description": "test mr description",
|
||||
"state": "opened"}`))
|
||||
|
||||
fakeHTTP.RegisterResponder("POST", `/projects/OWNER/REPO/merge_requests/123/approve`,
|
||||
httpmock.NewStringResponse(201, "{}"),
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, `/projects/OWNER/REPO/merge_requests/123/approve`,
|
||||
httpmock.NewStringResponse(http.StatusCreated, "{}"),
|
||||
)
|
||||
|
||||
mrID := "123"
|
||||
|
|
|
@ -57,8 +57,8 @@ func TestMrApprove(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(200, `{
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -66,8 +66,8 @@ func TestMrApprove(t *testing.T) {
|
|||
"description": "test mr description",
|
||||
"state": "opened"}`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `/projects/OWNER/REPO/merge_requests/123/approval_state`,
|
||||
httpmock.NewFileResponse(200, "./fixtures/approvalState.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `/projects/OWNER/REPO/merge_requests/123/approval_state`,
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/approvalState.json"))
|
||||
|
||||
mrID := "123"
|
||||
output, err := runCommand(fakeHTTP, mrID)
|
||||
|
|
|
@ -58,8 +58,8 @@ func TestMrApprove(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(200, `{
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -67,13 +67,13 @@ func TestMrApprove(t *testing.T) {
|
|||
"description": "test mr description",
|
||||
"state": "opened"}`))
|
||||
|
||||
fakeHTTP.RegisterResponder("PUT", `/projects/OWNER/REPO/merge_requests/123`,
|
||||
fakeHTTP.RegisterResponder(http.MethodPut, `/projects/OWNER/REPO/merge_requests/123`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
rb, _ := io.ReadAll(req.Body)
|
||||
|
||||
// ensure CLI updates MR to closed
|
||||
assert.Contains(t, string(rb), "\"state_event\":\"close\"")
|
||||
resp, _ := httpmock.NewStringResponse(200, `{
|
||||
resp, _ := httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
|
|
@ -145,9 +145,9 @@ func TestPRDiff_no_current_mr(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `[]`), nil
|
||||
return httpmock.NewStringResponse(http.StatusOK, `[]`), nil
|
||||
},
|
||||
)
|
||||
_, err := runCommand(nil, false, "")
|
||||
|
@ -161,9 +161,9 @@ func TestMRDiff_argument_not_found(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -173,9 +173,9 @@ func TestMRDiff_argument_not_found(t *testing.T) {
|
|||
},
|
||||
)
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(404, ""), errors.New("404 not found")
|
||||
return httpmock.NewStringResponse(http.StatusNotFound, ""), errors.New("404 not found")
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -190,9 +190,9 @@ func TestMRDiff_notty(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `[{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `[{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -201,9 +201,9 @@ func TestMRDiff_notty(t *testing.T) {
|
|||
"state": "merged"}]`), nil
|
||||
},
|
||||
)
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -227,9 +227,9 @@ func TestMRDiff_tty(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `[{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `[{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -239,9 +239,9 @@ func TestMRDiff_tty(t *testing.T) {
|
|||
},
|
||||
)
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
"project_id": 3,
|
||||
|
@ -260,9 +260,9 @@ func TestMRDiff_tty(t *testing.T) {
|
|||
}
|
||||
|
||||
func DiffTest() string {
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `[{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `[{
|
||||
"id": 110,
|
||||
"head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
|
||||
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
|
||||
|
@ -274,9 +274,9 @@ func DiffTest() string {
|
|||
}]`), nil
|
||||
},
|
||||
)
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions/110`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/OWNER%2FREPO/merge_requests/123/versions/110`,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
return httpmock.NewStringResponse(200, `{
|
||||
return httpmock.NewStringResponse(http.StatusOK, `{
|
||||
"id": 110,
|
||||
"head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
|
||||
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
|
||||
|
|
|
@ -30,8 +30,8 @@ func TestMergeRequestClosesIssues_byID(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/123",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/123",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
|
@ -39,8 +39,8 @@ func TestMergeRequestClosesIssues_byID(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/123/closes_issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/closesIssuesList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/123/closes_issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/closesIssuesList.json"))
|
||||
|
||||
cli := "123"
|
||||
output, err := runCommand(fakeHTTP, true, cli)
|
||||
|
@ -69,8 +69,8 @@ func TestMergeRequestClosesIssues_currentBranch(t *testing.T) {
|
|||
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/api/v4/projects/OWNER/REPO/merge_requests?per_page=30&source_branch=current_branch",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/api/v4/projects/OWNER/REPO/merge_requests?per_page=30&source_branch=current_branch",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[{
|
||||
"id":123,
|
||||
"iid":123,
|
||||
|
@ -79,8 +79,8 @@ func TestMergeRequestClosesIssues_currentBranch(t *testing.T) {
|
|||
}]
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/api/v4/projects/OWNER/REPO/merge_requests/123",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/api/v4/projects/OWNER/REPO/merge_requests/123",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 123,
|
||||
"iid": 123,
|
||||
|
@ -88,8 +88,8 @@ func TestMergeRequestClosesIssues_currentBranch(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/api/v4/projects/OWNER/REPO/merge_requests/123/closes_issues",
|
||||
httpmock.NewFileResponse(200, "./fixtures/closesIssuesList.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/api/v4/projects/OWNER/REPO/merge_requests/123/closes_issues",
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/closesIssuesList.json"))
|
||||
|
||||
output, err := runCommand(fakeHTTP, true, "")
|
||||
if err != nil {
|
||||
|
|
|
@ -79,8 +79,8 @@ func TestMergeRequestList_tty(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{
|
||||
"state" : "opened",
|
||||
|
@ -143,11 +143,11 @@ func TestMergeRequestList_tty_withFlags(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(200, `[]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[]`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/users",
|
||||
httpmock.NewStringResponse(200, `[{"id" : 1, "iid" : 1, "username": "john_smith"}]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/users",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[{"id" : 1, "iid" : 1, "username": "john_smith"}]`))
|
||||
|
||||
output, err := runCommand(fakeHTTP, true, "--opened -P1 -p100 -a someuser -l bug -m1", nil, "")
|
||||
if err != nil {
|
||||
|
@ -164,8 +164,8 @@ func TestMergeRequestList_tty_withFlags(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/groups/GROUP/merge_requests",
|
||||
httpmock.NewStringResponse(200, `[]`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/groups/GROUP/merge_requests",
|
||||
httpmock.NewStringResponse(http.StatusOK, `[]`))
|
||||
|
||||
output, err := runCommand(fakeHTTP, true, "--group GROUP", nil, "")
|
||||
if err != nil {
|
||||
|
@ -225,8 +225,8 @@ func TestMergeRequestList_hyperlinks(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{
|
||||
"state" : "opened",
|
||||
|
@ -321,8 +321,8 @@ func TestMergeRequestList_labels(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
path := fmt.Sprintf("/api/v4/projects/OWNER/REPO/merge_requests?%s", test.expectedQuery)
|
||||
fakeHTTP.RegisterResponder("GET", path,
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, path,
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{
|
||||
"state" : "opened",
|
||||
|
|
|
@ -57,11 +57,11 @@ func TestMrApprove(t *testing.T) {
|
|||
fakeHTTP := httpmock.New()
|
||||
defer fakeHTTP.Verify(t)
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewFileResponse(200, "./fixtures/mergeableMr.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, `/projects/OWNER/REPO/merge_requests/123`,
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/mergeableMr.json"))
|
||||
|
||||
fakeHTTP.RegisterResponder("PUT", `/projects/OWNER/REPO/merge_requests/123/merge`,
|
||||
httpmock.NewFileResponse(200, "./fixtures/mergedMr.json"))
|
||||
fakeHTTP.RegisterResponder(http.MethodPut, `/projects/OWNER/REPO/merge_requests/123/merge`,
|
||||
httpmock.NewFileResponse(http.StatusOK, "./fixtures/mergedMr.json"))
|
||||
|
||||
mrID := "123"
|
||||
output, err := runCommand(fakeHTTP, mrID)
|
||||
|
|
|
@ -34,8 +34,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("--message flag specified", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(201, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"id": 301,
|
||||
"created_at": "2013-10-02T08:57:14Z",
|
||||
|
@ -47,8 +47,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -67,8 +67,8 @@ func Test_NewCmdNote(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("merge request not found", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/122",
|
||||
httpmock.NewStringResponse(404, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/122",
|
||||
httpmock.NewStringResponse(http.StatusNotFound, `
|
||||
{
|
||||
"message" : "merge request not found"
|
||||
}
|
||||
|
@ -86,15 +86,15 @@ func Test_NewCmdNote_error(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("note could not be created", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(401, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusUnauthorized, `
|
||||
{
|
||||
"message" : "Unauthorized"
|
||||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -114,8 +114,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("message provided", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("POST", "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(201, `
|
||||
fakeHTTP.RegisterResponder(http.MethodPost, "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"id": 301,
|
||||
"created_at": "2013-10-02T08:57:14Z",
|
||||
|
@ -127,8 +127,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -150,8 +150,8 @@ func Test_mrNoteCreate_prompt(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("message is empty", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -178,8 +178,8 @@ func Test_mrNoteCreate_no_duplicate(t *testing.T) {
|
|||
defer fakeHTTP.Verify(t)
|
||||
|
||||
t.Run("message provided", func(t *testing.T) {
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
{
|
||||
"id": 1,
|
||||
"iid": 1,
|
||||
|
@ -187,8 +187,8 @@ func Test_mrNoteCreate_no_duplicate(t *testing.T) {
|
|||
}
|
||||
`))
|
||||
|
||||
fakeHTTP.RegisterResponder("GET", "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(200, `
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, "/projects/OWNER/REPO/merge_requests/1/notes",
|
||||
httpmock.NewStringResponse(http.StatusOK, `
|
||||
[
|
||||
{"id": 0, "body": "aaa"},
|
||||
{"id": 111, "body": "bbb"},
|
||||
|
|
|
@ -53,7 +53,7 @@ func Test_downloadAssets(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fullUrl := assetUrl + tt.filename
|
||||
fakeHTTP.RegisterResponder("GET", fullUrl, httpmock.NewStringResponse(200, `test_data`))
|
||||
fakeHTTP.RegisterResponder(http.MethodGet, fullUrl, httpmock.NewStringResponse(http.StatusOK, `test_data`))
|
||||
|
||||
io, _, _, _ := iostreams.Test()
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestNewCheckUpdateCmd(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.NewStringResponder(200, `[{"tag_name": "v1.11.1",
|
||||
"name": "v1.11.1",
|
||||
"created_at": "2020-11-03T05:33:29Z",
|
||||
|
@ -76,7 +76,7 @@ func TestNewCheckUpdateCmd_error(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.NewErrorResponder(fmt.Errorf("an error expected")))
|
||||
|
||||
factory, _, stdout, stderr, err := makeTestFactory()
|
||||
|
@ -93,7 +93,7 @@ func TestNewCheckUpdateCmd_no_release(t *testing.T) {
|
|||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
httpmock.RegisterResponder("GET", `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.RegisterResponder(http.MethodGet, `https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases`,
|
||||
httpmock.NewStringResponder(200, `[]`))
|
||||
|
||||
factory, _, stdout, stderr, err := makeTestFactory()
|
||||
|
|
|
@ -93,16 +93,16 @@ func Test_deleteRun(t *testing.T) {
|
|||
}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("DELETE", "/api/v4/projects/owner%2Frepo/variables/TEST_VAR?filter%5Benvironment_scope%5D=%2A",
|
||||
httpmock.NewStringResponse(204, " "),
|
||||
reg.RegisterResponder(http.MethodDelete, "/api/v4/projects/owner%2Frepo/variables/TEST_VAR?filter%5Benvironment_scope%5D=%2A",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, " "),
|
||||
)
|
||||
|
||||
reg.RegisterResponder("DELETE", "/api/v4/projects/owner%2Frepo/variables/TEST_VAR?filter%5Benvironment_scope%5D=stage",
|
||||
httpmock.NewStringResponse(204, " "),
|
||||
reg.RegisterResponder(http.MethodDelete, "/api/v4/projects/owner%2Frepo/variables/TEST_VAR?filter%5Benvironment_scope%5D=stage",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, " "),
|
||||
)
|
||||
|
||||
reg.RegisterResponder("DELETE", "/api/v4/groups/testGroup/variables/TEST_VAR",
|
||||
httpmock.NewStringResponse(204, " "),
|
||||
reg.RegisterResponder(http.MethodDelete, "/api/v4/groups/testGroup/variables/TEST_VAR",
|
||||
httpmock.NewStringResponse(http.StatusNoContent, " "),
|
||||
)
|
||||
|
||||
httpClient := func() (*gitlab.Client, error) {
|
||||
|
|
|
@ -93,8 +93,8 @@ func Test_exportRun_project(t *testing.T) {
|
|||
}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("GET", "https://gitlab.com/api/v4/projects/owner%2Frepo/variables?page=1&per_page=10",
|
||||
httpmock.NewJSONResponse(200, nil),
|
||||
reg.RegisterResponder(http.MethodGet, "https://gitlab.com/api/v4/projects/owner%2Frepo/variables?page=1&per_page=10",
|
||||
httpmock.NewJSONResponse(http.StatusOK, nil),
|
||||
)
|
||||
|
||||
io, _, stdout, _ := iostreams.Test()
|
||||
|
@ -124,8 +124,8 @@ func Test_exportRun_group(t *testing.T) {
|
|||
}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("GET", "https://gitlab.com/api/v4/groups/GROUP/variables?page=7&per_page=77",
|
||||
httpmock.NewJSONResponse(200, nil),
|
||||
reg.RegisterResponder(http.MethodGet, "https://gitlab.com/api/v4/groups/GROUP/variables?page=7&per_page=77",
|
||||
httpmock.NewJSONResponse(http.StatusOK, nil),
|
||||
)
|
||||
|
||||
io, _, stdout, _ := iostreams.Test()
|
||||
|
|
|
@ -122,8 +122,8 @@ func Test_getRun_project(t *testing.T) {
|
|||
EnvironmentScope: "*",
|
||||
}
|
||||
|
||||
reg.RegisterResponder("GET", "/projects/owner/repo/variables/TEST_VAR",
|
||||
httpmock.NewJSONResponse(200, body),
|
||||
reg.RegisterResponder(http.MethodGet, "/projects/owner/repo/variables/TEST_VAR",
|
||||
httpmock.NewJSONResponse(http.StatusOK, body),
|
||||
)
|
||||
|
||||
io, _, stdout, _ := iostreams.Test()
|
||||
|
|
|
@ -122,8 +122,8 @@ func Test_setRun_project(t *testing.T) {
|
|||
reg := &httpmock.Mocker{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("POST", "/projects/owner/repo/variables",
|
||||
httpmock.NewStringResponse(201, `
|
||||
reg.RegisterResponder(http.MethodPost, "/projects/owner/repo/variables",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"key": "NEW_VARIABLE",
|
||||
"value": "new value",
|
||||
|
@ -160,8 +160,8 @@ func Test_setRun_group(t *testing.T) {
|
|||
reg := &httpmock.Mocker{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("POST", "/groups/mygroup/variables",
|
||||
httpmock.NewStringResponse(201, `
|
||||
reg.RegisterResponder(http.MethodPost, "/groups/mygroup/variables",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"key": "NEW_VARIABLE",
|
||||
"value": "new value",
|
||||
|
|
|
@ -122,8 +122,8 @@ func Test_updateRun_project(t *testing.T) {
|
|||
reg := &httpmock.Mocker{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("PUT", "/projects/owner/repo/variables/TEST_VARIABLE",
|
||||
httpmock.NewStringResponse(201, `
|
||||
reg.RegisterResponder(http.MethodPut, "/projects/owner/repo/variables/TEST_VARIABLE",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"key": "TEST_VARIABLE",
|
||||
"value": "foo",
|
||||
|
@ -160,8 +160,8 @@ func Test_updateRun_group(t *testing.T) {
|
|||
reg := &httpmock.Mocker{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
reg.RegisterResponder("PUT", "/groups/mygroup/variables/TEST_VARIABLE",
|
||||
httpmock.NewStringResponse(201, `
|
||||
reg.RegisterResponder(http.MethodPut, "/groups/mygroup/variables/TEST_VARIABLE",
|
||||
httpmock.NewStringResponse(http.StatusCreated, `
|
||||
{
|
||||
"key": "TEST_VARIABLE",
|
||||
"value": "blargh",
|
||||
|
|
Loading…
Reference in New Issue