diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2022-01-24 18:45:53 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2022-01-27 15:51:08 +0300 |
commit | 6c91c8e8b0917567fdcd6b14b075c8bdf20d2c5f (patch) | |
tree | 38f87248a6ee7993e137aa74580c3860558511a0 /internal/gitaly/service/operations/submodules_test.go | |
parent | b4a1fffaa707d5f0dc19af21f06947d0274db878 (diff) |
Automatically clean up testhelper.Context
testhelper.Context() currently return a cancellation function as a
second return value. Majority of the tests do not need to explicitly
cancel the context but they simply defer its cancellation to clean up
after the test. Given this, we can reduce the test verbosity and make
testhelper.Context easier to compose by removing the unnecessary second
return value. This adds a t.Cleanup function to automatically cancel the
context at the end of the tests and omits the returned cancellation
function.
Tests which simply `defer cancel()` have had the extra call removed. Some
tests explicitly call the cancellation, and these tests have been modified
to add context.WithCancel around the testhelper.Context call. There are a
few loctions where testing.TB was passed down to test helpers that create the
context.
Diffstat (limited to 'internal/gitaly/service/operations/submodules_test.go')
-rw-r--r-- | internal/gitaly/service/operations/submodules_test.go | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go index 246286fb3..d45c0d2aa 100644 --- a/internal/gitaly/service/operations/submodules_test.go +++ b/internal/gitaly/service/operations/submodules_test.go @@ -20,9 +20,7 @@ import ( func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx) @@ -104,9 +102,7 @@ func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) { func TestUserUpdateSubmoduleStableID(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, cfg, repoProto, _, client := setupOperationsService(t, ctx) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -152,9 +148,7 @@ func TestUserUpdateSubmoduleStableID(t *testing.T) { func TestUserUpdateSubmoduleQuarantine(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, cfg, repoProto, repoPath, client := setupOperationsService(t, ctx) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -193,9 +187,7 @@ func TestUserUpdateSubmoduleQuarantine(t *testing.T) { func TestFailedUserUpdateSubmoduleRequestDueToValidations(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, _, repo, _, client := setupOperationsService(t, ctx) @@ -313,9 +305,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToValidations(t *testing.T) { func TestFailedUserUpdateSubmoduleRequestDueToInvalidBranch(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, _, repo, _, client := setupOperationsService(t, ctx) @@ -335,9 +325,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidBranch(t *testing.T) { func TestFailedUserUpdateSubmoduleRequestDueToInvalidSubmodule(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, _, repo, _, client := setupOperationsService(t, ctx) @@ -357,9 +345,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidSubmodule(t *testing.T) { func TestFailedUserUpdateSubmoduleRequestDueToSameReference(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, _, repo, _, client := setupOperationsService(t, ctx) @@ -382,9 +368,7 @@ func TestFailedUserUpdateSubmoduleRequestDueToSameReference(t *testing.T) { func TestFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T) { t.Parallel() - - ctx, cancel := testhelper.Context() - defer cancel() + ctx := testhelper.Context(t) ctx, cfg, _, _, client := setupOperationsService(t, ctx) |