diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-10-04 11:43:26 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-10-08 10:46:19 +0300 |
commit | 171eb484b55b5450fa76956bb0cd44a169e4a664 (patch) | |
tree | fd14633da4845a84ad2e74be32d650323dc0356c /cmd | |
parent | 86b813312e32540e7b7b57cda7ffd4be32b09397 (diff) |
remove-repository: Reduce code duplication
Let's reuse the repository creation function
introduced with the list-untracked-repositories
Praefect sub-command in a previous commit. This
function uses the test name in the repository
relative path. This can avoid possible side effects
from one test to affect other tests.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/praefect/subcmd_remove_repository_test.go | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/cmd/praefect/subcmd_remove_repository_test.go b/cmd/praefect/subcmd_remove_repository_test.go index 9dab2f0a6..aa18bbdce 100644 --- a/cmd/praefect/subcmd_remove_repository_test.go +++ b/cmd/praefect/subcmd_remove_repository_test.go @@ -122,29 +122,10 @@ func TestRemoveRepository_Exec(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - createRepo := func(t *testing.T, storageName, relativePath string) *gitalypb.Repository { - t.Helper() - repo := &gitalypb.Repository{ - StorageName: storageName, - RelativePath: relativePath, - } - for i := 0; true; i++ { - _, err := repoClient.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: repo}) - if err != nil { - require.Regexp(t, "(no healthy nodes)|(no such file or directory)|(connection refused)", err.Error()) - require.Less(t, i, 100, "praefect doesn't serve for too long") - time.Sleep(50 * time.Millisecond) - } else { - break - } - } - return repo - } - praefectStorage := conf.VirtualStorages[0].Name t.Run("ok", func(t *testing.T) { - repo := createRepo(t, praefectStorage, "path/to/test/repo") + repo := createRepo(t, ctx, repoClient, praefectStorage, t.Name()) cmd := &removeRepository{ logger: testhelper.NewTestLogger(t), virtualStorage: repo.StorageName, @@ -164,7 +145,7 @@ func TestRemoveRepository_Exec(t *testing.T) { }) t.Run("no info about repository on praefect", func(t *testing.T) { - repo := createRepo(t, praefectStorage, "path/to/test/repo") + repo := createRepo(t, ctx, repoClient, praefectStorage, t.Name()) repoStore := datastore.NewPostgresRepositoryStore(db.DB, nil) require.NoError(t, repoStore.DeleteRepository( ctx, repo.StorageName, repo.RelativePath, []string{g1Cfg.Storages[0].Name, g2Cfg.Storages[0].Name}, @@ -193,7 +174,7 @@ func TestRemoveRepository_Exec(t *testing.T) { }) t.Run("one of gitalies is out of service", func(t *testing.T) { - repo := createRepo(t, praefectStorage, "path/to/test/repo") + repo := createRepo(t, ctx, repoClient, praefectStorage, t.Name()) g2Srv.Shutdown() logger := testhelper.NewTestLogger(t) |