Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-09 13:39:56 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-15 08:53:46 +0300
commita6ef1b60f8a2dc74c27c64cd14d7a2e762e784eb (patch)
treeadd4eeb79ca6cccb3b0f31b9e4ee45ecb244c301
parent00f6ba6b821198204bd9a4aa1670c8cedc6e1a98 (diff)
ssh: Use table-driven tests instead of multiple indirections
Because SSHUploadPack can either be invoked with or without sidechannel and with and without the pack-objects cache we need to re-run some tests multiple times with all combinations. This is solved via separate tests which call into the same function, but in a rather weird way where `TestFn()` calls `testFn()`, which then again calls `testFn2()`. This is mighty confusing. Refactor the test to instead be table-driven to simplify it.
-rw-r--r--internal/gitaly/service/ssh/upload_pack_test.go30
1 files changed, 10 insertions, 20 deletions
diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go
index 094e471ef..6b4363d92 100644
--- a/internal/gitaly/service/ssh/upload_pack_test.go
+++ b/internal/gitaly/service/ssh/upload_pack_test.go
@@ -206,24 +206,16 @@ func TestFailedUploadPackRequestDueToValidationError(t *testing.T) {
func TestUploadPackCloneSuccess(t *testing.T) {
t.Parallel()
- runTestWithAndWithoutConfigOptions(t, testUploadPackCloneSuccess, testcfg.WithPackObjectsCacheEnabled())
-}
-
-func testUploadPackCloneSuccess(t *testing.T, opts ...testcfg.Option) {
- testUploadPackCloneSuccess2(t, false, opts...)
-}
-
-func TestUploadPackWithSidechannelCloneSuccess(t *testing.T) {
- t.Parallel()
-
- runTestWithAndWithoutConfigOptions(t, testUploadPackWithSidechannelCloneSuccess, testcfg.WithPackObjectsCacheEnabled())
-}
-
-func testUploadPackWithSidechannelCloneSuccess(t *testing.T, opts ...testcfg.Option) {
- testUploadPackCloneSuccess2(t, true, opts...)
+ for _, withSidechannel := range []bool{true, false} {
+ t.Run(fmt.Sprintf("sidechannel=%v", withSidechannel), func(t *testing.T) {
+ runTestWithAndWithoutConfigOptions(t, func(t *testing.T, opts ...testcfg.Option) {
+ testUploadPackCloneSuccess(t, withSidechannel, opts...)
+ })
+ })
+ }
}
-func testUploadPackCloneSuccess2(t *testing.T, sidechannel bool, opts ...testcfg.Option) {
+func testUploadPackCloneSuccess(t *testing.T, sidechannel bool, opts ...testcfg.Option) {
ctx := testhelper.Context(t)
cfg := testcfg.Build(t, opts...)
@@ -239,7 +231,7 @@ func testUploadPackCloneSuccess2(t *testing.T, sidechannel bool, opts ...testcfg
Seed: gittest.SeedGitLabTest,
})
- tests := []struct {
+ for _, tc := range []struct {
desc string
cloneFlags []git.Option
deepen float64
@@ -255,9 +247,7 @@ func testUploadPackCloneSuccess2(t *testing.T, sidechannel bool, opts ...testcfg
},
deepen: 1,
},
- }
-
- for _, tc := range tests {
+ } {
t.Run(tc.desc, func(t *testing.T) {
localRepoPath := testhelper.TempDir(t)