summaryrefslogtreecommitdiff
path: root/internal/command
diff options
context:
space:
mode:
Diffstat (limited to 'internal/command')
-rw-r--r--internal/command/discover/discover_test.go50
-rw-r--r--internal/command/healthcheck/healthcheck_test.go2
-rw-r--r--internal/command/personalaccesstoken/personalaccesstoken_test.go6
-rw-r--r--internal/command/twofactorrecover/twofactorrecover_test.go6
-rw-r--r--internal/command/twofactorverify/twofactorverify_test.go2
5 files changed, 30 insertions, 36 deletions
diff --git a/internal/command/discover/discover_test.go b/internal/command/discover/discover_test.go
index ccbfa7e..df9ca47 100644
--- a/internal/command/discover/discover_test.go
+++ b/internal/command/discover/discover_test.go
@@ -16,33 +16,31 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
)
-var (
- requests = []testserver.TestRequestHandler{
- {
- Path: "/api/v4/internal/discover",
- Handler: func(w http.ResponseWriter, r *http.Request) {
- if r.URL.Query().Get("key_id") == "1" || r.URL.Query().Get("username") == "alex-doe" {
- body := map[string]interface{}{
- "id": 2,
- "username": "alex-doe",
- "name": "Alex Doe",
- }
- json.NewEncoder(w).Encode(body)
- } else if r.URL.Query().Get("username") == "broken_message" {
- body := map[string]string{
- "message": "Forbidden!",
- }
- w.WriteHeader(http.StatusForbidden)
- json.NewEncoder(w).Encode(body)
- } else if r.URL.Query().Get("username") == "broken" {
- w.WriteHeader(http.StatusInternalServerError)
- } else {
- fmt.Fprint(w, "null")
+var requests = []testserver.TestRequestHandler{
+ {
+ Path: "/api/v4/internal/discover",
+ Handler: func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Query().Get("key_id") == "1" || r.URL.Query().Get("username") == "alex-doe" {
+ body := map[string]interface{}{
+ "id": 2,
+ "username": "alex-doe",
+ "name": "Alex Doe",
+ }
+ json.NewEncoder(w).Encode(body)
+ } else if r.URL.Query().Get("username") == "broken_message" {
+ body := map[string]string{
+ "message": "Forbidden!",
}
- },
+ w.WriteHeader(http.StatusForbidden)
+ json.NewEncoder(w).Encode(body)
+ } else if r.URL.Query().Get("username") == "broken" {
+ w.WriteHeader(http.StatusInternalServerError)
+ } else {
+ fmt.Fprint(w, "null")
+ }
},
- }
-)
+ },
+}
func TestExecute(t *testing.T) {
url := testserver.StartSocketHttpServer(t, requests)
@@ -112,7 +110,7 @@ func TestFailingExecute(t *testing.T) {
{
desc: "When the API fails",
arguments: &commandargs.Shell{GitlabUsername: "broken"},
- expectedError: "Failed to get username: Internal API error (500)",
+ expectedError: "Failed to get username: Internal API unreachable",
},
}
diff --git a/internal/command/healthcheck/healthcheck_test.go b/internal/command/healthcheck/healthcheck_test.go
index f642226..12a8444 100644
--- a/internal/command/healthcheck/healthcheck_test.go
+++ b/internal/command/healthcheck/healthcheck_test.go
@@ -84,5 +84,5 @@ func TestFailingAPIExecute(t *testing.T) {
err := cmd.Execute(context.Background())
require.Empty(t, buffer.String())
- require.EqualError(t, err, "Internal API available: FAILED - Internal API error (500)")
+ require.EqualError(t, err, "Internal API available: FAILED - Internal API unreachable")
}
diff --git a/internal/command/personalaccesstoken/personalaccesstoken_test.go b/internal/command/personalaccesstoken/personalaccesstoken_test.go
index daa5834..492f745 100644
--- a/internal/command/personalaccesstoken/personalaccesstoken_test.go
+++ b/internal/command/personalaccesstoken/personalaccesstoken_test.go
@@ -17,9 +17,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/personalaccesstoken"
)
-var (
- requests []testserver.TestRequestHandler
-)
+var requests []testserver.TestRequestHandler
func setup(t *testing.T) {
requests = []testserver.TestRequestHandler{
@@ -147,7 +145,7 @@ func TestExecute(t *testing.T) {
GitlabKeyId: "broken",
SshArgs: []string{cmdname, "newtoken", "read_api,read_repository"},
},
- expectedError: "Internal API error (500)",
+ expectedError: "Internal API unreachable",
},
{
desc: "Without KeyID or User",
diff --git a/internal/command/twofactorrecover/twofactorrecover_test.go b/internal/command/twofactorrecover/twofactorrecover_test.go
index 81b4dff..7e20a06 100644
--- a/internal/command/twofactorrecover/twofactorrecover_test.go
+++ b/internal/command/twofactorrecover/twofactorrecover_test.go
@@ -18,9 +18,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/twofactorrecover"
)
-var (
- requests []testserver.TestRequestHandler
-)
+var requests []testserver.TestRequestHandler
func setup(t *testing.T) {
requests = []testserver.TestRequestHandler{
@@ -99,7 +97,7 @@ func TestExecute(t *testing.T) {
desc: "With API fails",
arguments: &commandargs.Shell{GitlabKeyId: "broken"},
answer: "yes\n",
- expectedOutput: question + errorHeader + "Internal API error (500)\n",
+ expectedOutput: question + errorHeader + "Internal API unreachable\n",
},
{
desc: "With missing arguments",
diff --git a/internal/command/twofactorverify/twofactorverify_test.go b/internal/command/twofactorverify/twofactorverify_test.go
index 640d3ed..213c025 100644
--- a/internal/command/twofactorverify/twofactorverify_test.go
+++ b/internal/command/twofactorverify/twofactorverify_test.go
@@ -136,7 +136,7 @@ func TestExecute(t *testing.T) {
{
desc: "With API fails",
arguments: &commandargs.Shell{GitlabKeyId: "broken"},
- expectedOutput: errorHeader + "Internal API error (500)\n",
+ expectedOutput: errorHeader + "Internal API unreachable\n",
},
{
desc: "With missing arguments",