diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2021-03-17 21:18:42 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2021-03-17 21:23:07 +0300 |
commit | ee41d0dfb7b02a19f5926bfe24dbad1df417a29e (patch) | |
tree | 130f2777342645018f3f6b797ee0083d65910889 /internal/command | |
parent | 4b40a2cb8c71a5b490cad4c8e1ad2dc0e9b39548 (diff) | |
download | gitlab-shell-ee41d0dfb7b02a19f5926bfe24dbad1df417a29e.tar.gz |
Replace cleanup functions with t.Cleanup
In this case we don't need to propagate cleanup
function. It simplifies the code.
Diffstat (limited to 'internal/command')
15 files changed, 32 insertions, 57 deletions
diff --git a/internal/command/authorizedkeys/authorized_keys_test.go b/internal/command/authorizedkeys/authorized_keys_test.go index ab44580..7048b57 100644 --- a/internal/command/authorizedkeys/authorized_keys_test.go +++ b/internal/command/authorizedkeys/authorized_keys_test.go @@ -43,8 +43,7 @@ var ( ) func TestExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) defaultConfig := &config.Config{RootDir: "/tmp", GitlabUrl: url} diff --git a/internal/command/discover/discover_test.go b/internal/command/discover/discover_test.go index 5431410..7989c27 100644 --- a/internal/command/discover/discover_test.go +++ b/internal/command/discover/discover_test.go @@ -45,8 +45,7 @@ var ( ) func TestExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) testCases := []struct { desc string @@ -93,8 +92,7 @@ func TestExecute(t *testing.T) { } func TestFailingExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) testCases := []struct { desc string diff --git a/internal/command/healthcheck/healthcheck_test.go b/internal/command/healthcheck/healthcheck_test.go index d05e563..c010c17 100644 --- a/internal/command/healthcheck/healthcheck_test.go +++ b/internal/command/healthcheck/healthcheck_test.go @@ -45,8 +45,7 @@ func buildTestHandlers(code int, rsp *healthcheck.Response) []testserver.TestReq } func TestExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, okHandlers) - defer cleanup() + url := testserver.StartSocketHttpServer(t, okHandlers) buffer := &bytes.Buffer{} cmd := &Command{ @@ -61,8 +60,7 @@ func TestExecute(t *testing.T) { } func TestFailingRedisExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, badRedisHandlers) - defer cleanup() + url := testserver.StartSocketHttpServer(t, badRedisHandlers) buffer := &bytes.Buffer{} cmd := &Command{ @@ -76,8 +74,7 @@ func TestFailingRedisExecute(t *testing.T) { } func TestFailingAPIExecute(t *testing.T) { - url, cleanup := testserver.StartSocketHttpServer(t, brokenHandlers) - defer cleanup() + url := testserver.StartSocketHttpServer(t, brokenHandlers) buffer := &bytes.Buffer{} cmd := &Command{ diff --git a/internal/command/lfsauthenticate/lfsauthenticate_test.go b/internal/command/lfsauthenticate/lfsauthenticate_test.go index 55998ab..63aecb0 100644 --- a/internal/command/lfsauthenticate/lfsauthenticate_test.go +++ b/internal/command/lfsauthenticate/lfsauthenticate_test.go @@ -21,8 +21,7 @@ import ( func TestFailedRequests(t *testing.T) { requests := requesthandlers.BuildDisallowedByApiHandlers(t) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) testCases := []struct { desc string @@ -118,8 +117,7 @@ func TestLfsAuthenticateRequests(t *testing.T) { }, } - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) testCases := []struct { desc string diff --git a/internal/command/personalaccesstoken/personalaccesstoken_test.go b/internal/command/personalaccesstoken/personalaccesstoken_test.go index aa56ce9..37d5ae7 100644 --- a/internal/command/personalaccesstoken/personalaccesstoken_test.go +++ b/internal/command/personalaccesstoken/personalaccesstoken_test.go @@ -71,8 +71,7 @@ const ( func TestExecute(t *testing.T) { setup(t) - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) testCases := []struct { desc string diff --git a/internal/command/receivepack/gitalycall_test.go b/internal/command/receivepack/gitalycall_test.go index d756248..9a1019d 100644 --- a/internal/command/receivepack/gitalycall_test.go +++ b/internal/command/receivepack/gitalycall_test.go @@ -19,12 +19,10 @@ import ( ) func TestReceivePack(t *testing.T) { - gitalyAddress, _, cleanup := testserver.StartGitalyServer(t) - defer cleanup() + gitalyAddress, _ := testserver.StartGitalyServer(t) requests := requesthandlers.BuildAllowedWithGitalyHandlers(t, gitalyAddress) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) testCases := []struct { username string diff --git a/internal/command/receivepack/receivepack_test.go b/internal/command/receivepack/receivepack_test.go index 44cb680..0f23492 100644 --- a/internal/command/receivepack/receivepack_test.go +++ b/internal/command/receivepack/receivepack_test.go @@ -16,23 +16,21 @@ import ( func TestForbiddenAccess(t *testing.T) { requests := requesthandlers.BuildDisallowedByApiHandlers(t) - cmd, _, cleanup := setup(t, "disallowed", requests) - defer cleanup() + cmd, _ := setup(t, "disallowed", requests) err := cmd.Execute(context.Background()) require.Equal(t, "Disallowed by API call", err.Error()) } func TestCustomReceivePack(t *testing.T) { - cmd, output, cleanup := setup(t, "1", requesthandlers.BuildAllowedWithCustomActionsHandlers(t)) - defer cleanup() + cmd, output := setup(t, "1", requesthandlers.BuildAllowedWithCustomActionsHandlers(t)) require.NoError(t, cmd.Execute(context.Background())) require.Equal(t, "customoutput", output.String()) } -func setup(t *testing.T, keyId string, requests []testserver.TestRequestHandler) (*Command, *bytes.Buffer, func()) { - url, cleanup := testserver.StartSocketHttpServer(t, requests) +func setup(t *testing.T, keyId string, requests []testserver.TestRequestHandler) (*Command, *bytes.Buffer) { + url := testserver.StartSocketHttpServer(t, requests) output := &bytes.Buffer{} input := bytes.NewBufferString("input") @@ -43,5 +41,5 @@ func setup(t *testing.T, keyId string, requests []testserver.TestRequestHandler) ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, } - return cmd, output, cleanup + return cmd, output } diff --git a/internal/command/shared/accessverifier/accessverifier_test.go b/internal/command/shared/accessverifier/accessverifier_test.go index 8ad87b8..8e0b5f9 100644 --- a/internal/command/shared/accessverifier/accessverifier_test.go +++ b/internal/command/shared/accessverifier/accessverifier_test.go @@ -22,7 +22,7 @@ var ( action = commandargs.ReceivePack ) -func setup(t *testing.T) (*Command, *bytes.Buffer, *bytes.Buffer, func()) { +func setup(t *testing.T) (*Command, *bytes.Buffer, *bytes.Buffer) { requests := []testserver.TestRequestHandler{ { Path: "/api/v4/internal/allowed", @@ -50,7 +50,7 @@ func setup(t *testing.T) (*Command, *bytes.Buffer, *bytes.Buffer, func()) { }, } - url, cleanup := testserver.StartSocketHttpServer(t, requests) + url := testserver.StartSocketHttpServer(t, requests) errBuf := &bytes.Buffer{} outBuf := &bytes.Buffer{} @@ -58,12 +58,11 @@ func setup(t *testing.T) (*Command, *bytes.Buffer, *bytes.Buffer, func()) { readWriter := &readwriter.ReadWriter{Out: outBuf, ErrOut: errBuf} cmd := &Command{Config: &config.Config{GitlabUrl: url}, ReadWriter: readWriter} - return cmd, errBuf, outBuf, cleanup + return cmd, errBuf, outBuf } func TestMissingUser(t *testing.T) { - cmd, _, _, cleanup := setup(t) - defer cleanup() + cmd, _, _ := setup(t) cmd.Args = &commandargs.Shell{GitlabKeyId: "2"} _, err := cmd.Verify(context.Background(), action, repo) @@ -72,8 +71,7 @@ func TestMissingUser(t *testing.T) { } func TestConsoleMessages(t *testing.T) { - cmd, errBuf, outBuf, cleanup := setup(t) - defer cleanup() + cmd, errBuf, outBuf := setup(t) cmd.Args = &commandargs.Shell{GitlabKeyId: "1"} cmd.Verify(context.Background(), action, repo) diff --git a/internal/command/shared/customaction/customaction_test.go b/internal/command/shared/customaction/customaction_test.go index 119da5b..87ae2e4 100644 --- a/internal/command/shared/customaction/customaction_test.go +++ b/internal/command/shared/customaction/customaction_test.go @@ -54,8 +54,7 @@ func TestExecuteEOFSent(t *testing.T) { }, } - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) outBuf := &bytes.Buffer{} errBuf := &bytes.Buffer{} @@ -124,8 +123,7 @@ func TestExecuteNoEOFSent(t *testing.T) { }, } - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) outBuf := &bytes.Buffer{} errBuf := &bytes.Buffer{} diff --git a/internal/command/twofactorrecover/twofactorrecover_test.go b/internal/command/twofactorrecover/twofactorrecover_test.go index a53e055..01852f6 100644 --- a/internal/command/twofactorrecover/twofactorrecover_test.go +++ b/internal/command/twofactorrecover/twofactorrecover_test.go @@ -65,8 +65,7 @@ const ( func TestExecute(t *testing.T) { setup(t) - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) testCases := []struct { desc string diff --git a/internal/command/twofactorverify/twofactorverify_test.go b/internal/command/twofactorverify/twofactorverify_test.go index 9d5f54d..2e9e0ea 100644 --- a/internal/command/twofactorverify/twofactorverify_test.go +++ b/internal/command/twofactorverify/twofactorverify_test.go @@ -60,8 +60,7 @@ const ( func TestExecute(t *testing.T) { requests := setup(t) - url, cleanup := testserver.StartSocketHttpServer(t, requests) - defer cleanup() + url := testserver.StartSocketHttpServer(t, requests) testCases := []struct { desc string diff --git a/internal/command/uploadarchive/gitalycall_test.go b/internal/command/uploadarchive/gitalycall_test.go index f74093a..03223e9 100644 --- a/internal/command/uploadarchive/gitalycall_test.go +++ b/internal/command/uploadarchive/gitalycall_test.go @@ -18,12 +18,10 @@ import ( ) func TestUploadPack(t *testing.T) { - gitalyAddress, _, cleanup := testserver.StartGitalyServer(t) - defer cleanup() + gitalyAddress, _ := testserver.StartGitalyServer(t) requests := requesthandlers.BuildAllowedWithGitalyHandlers(t, gitalyAddress) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) output := &bytes.Buffer{} input := &bytes.Buffer{} diff --git a/internal/command/uploadarchive/uploadarchive_test.go b/internal/command/uploadarchive/uploadarchive_test.go index 5426569..c42c715 100644 --- a/internal/command/uploadarchive/uploadarchive_test.go +++ b/internal/command/uploadarchive/uploadarchive_test.go @@ -16,8 +16,7 @@ import ( func TestForbiddenAccess(t *testing.T) { requests := requesthandlers.BuildDisallowedByApiHandlers(t) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) output := &bytes.Buffer{} diff --git a/internal/command/uploadpack/gitalycall_test.go b/internal/command/uploadpack/gitalycall_test.go index e94a628..d945764 100644 --- a/internal/command/uploadpack/gitalycall_test.go +++ b/internal/command/uploadpack/gitalycall_test.go @@ -17,12 +17,10 @@ import ( ) func TestUploadPack(t *testing.T) { - gitalyAddress, testServer, cleanup := testserver.StartGitalyServer(t) - defer cleanup() + gitalyAddress, testServer := testserver.StartGitalyServer(t) requests := requesthandlers.BuildAllowedWithGitalyHandlers(t, gitalyAddress) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) output := &bytes.Buffer{} input := &bytes.Buffer{} @@ -42,7 +40,7 @@ func TestUploadPack(t *testing.T) { require.NoError(t, err) require.Equal(t, "UploadPack: "+repo, output.String()) - require.Eventually(t, func() bool{ + require.Eventually(t, func() bool { entries := hook.AllEntries() require.Equal(t, 2, len(entries)) diff --git a/internal/command/uploadpack/uploadpack_test.go b/internal/command/uploadpack/uploadpack_test.go index 20edb57..7b43ded 100644 --- a/internal/command/uploadpack/uploadpack_test.go +++ b/internal/command/uploadpack/uploadpack_test.go @@ -16,8 +16,7 @@ import ( func TestForbiddenAccess(t *testing.T) { requests := requesthandlers.BuildDisallowedByApiHandlers(t) - url, cleanup := testserver.StartHttpServer(t, requests) - defer cleanup() + url := testserver.StartHttpServer(t, requests) output := &bytes.Buffer{} |