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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-02-10 15:40:32 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-05-16 16:34:50 +0300
commit9c19ad66f4b691f47bf5fa900062b45bec36cd08 (patch)
tree7b42582f061f1263594e896df8402854f1a5ff3b
parent5553cc8f515bbcb0e7414710387f330074f1e27d (diff)
Replace custom db assertions with a call to RepositoryExists
TestRemoveRepository has some custom assertions to check whether DB records exist or not. This commit replaces those assertions by a call to RepositoryExists. RepositoryExists also checks in the database whether the repository exists or not, so this just replaces custom assertions by more use of production code.
-rw-r--r--cmd/praefect/subcmd_remove_repository_test.go51
1 files changed, 13 insertions, 38 deletions
diff --git a/cmd/praefect/subcmd_remove_repository_test.go b/cmd/praefect/subcmd_remove_repository_test.go
index f00be8d1d..1831d131b 100644
--- a/cmd/praefect/subcmd_remove_repository_test.go
+++ b/cmd/praefect/subcmd_remove_repository_test.go
@@ -104,6 +104,14 @@ func TestRemoveRepository_Exec(t *testing.T) {
praefectStorage := conf.VirtualStorages[0].Name
+ repositoryExists := func(t testing.TB, repo *gitalypb.Repository) bool {
+ response, err := gitalypb.NewRepositoryServiceClient(cc).RepositoryExists(ctx, &gitalypb.RepositoryExistsRequest{
+ Repository: repo,
+ })
+ require.NoError(t, err)
+ return response.GetExists()
+ }
+
t.Run("dry run", func(t *testing.T) {
var out bytes.Buffer
repo := createRepo(t, ctx, repoClient, praefectStorage, t.Name())
@@ -123,10 +131,7 @@ func TestRemoveRepository_Exec(t *testing.T) {
require.DirExists(t, filepath.Join(g2Cfg.Storages[0].Path, replicaPath))
assert.Contains(t, out.String(), "Repository found in the database.\n")
assert.Contains(t, out.String(), "Re-run the command with -apply to remove repositories from the database and disk.\n")
-
- repositoryRowExists, err := datastore.NewPostgresRepositoryStore(db, nil).RepositoryExists(ctx, cmd.virtualStorage, cmd.relativePath)
- require.NoError(t, err)
- require.True(t, repositoryRowExists)
+ require.True(t, repositoryExists(t, repo))
})
t.Run("ok", func(t *testing.T) {
@@ -147,13 +152,7 @@ func TestRemoveRepository_Exec(t *testing.T) {
assert.Contains(t, out.String(), "Repository found in the database.\n")
assert.Contains(t, out.String(), fmt.Sprintf("Attempting to remove %s from the database, and delete it from all gitaly nodes...\n", repo.RelativePath))
assert.Contains(t, out.String(), "Repository removal completed.")
-
- var repositoryRowExists bool
- require.NoError(t, db.QueryRow(
- `SELECT EXISTS(SELECT FROM repositories WHERE virtual_storage = $1 AND relative_path = $2)`,
- cmd.virtualStorage, cmd.relativePath,
- ).Scan(&repositoryRowExists))
- require.False(t, repositoryRowExists)
+ require.False(t, repositoryExists(t, repo))
})
t.Run("repository doesnt exist on one gitaly", func(t *testing.T) {
@@ -177,13 +176,7 @@ func TestRemoveRepository_Exec(t *testing.T) {
assert.Contains(t, out.String(), "Repository found in the database.\n")
assert.Contains(t, out.String(), fmt.Sprintf("Attempting to remove %s from the database, and delete it from all gitaly nodes...\n", repo.RelativePath))
assert.Contains(t, out.String(), "Repository removal completed.")
-
- var repositoryRowExists bool
- require.NoError(t, db.QueryRow(
- `SELECT EXISTS(SELECT FROM repositories WHERE virtual_storage = $1 AND relative_path = $2)`,
- cmd.virtualStorage, cmd.relativePath,
- ).Scan(&repositoryRowExists))
- require.False(t, repositoryRowExists)
+ require.False(t, repositoryExists(t, repo))
})
t.Run("no info about repository on praefect", func(t *testing.T) {
@@ -206,8 +199,7 @@ func TestRemoveRepository_Exec(t *testing.T) {
require.Error(t, cmd.Exec(flag.NewFlagSet("", flag.PanicOnError), conf), "repository is not being tracked in Praefect")
require.DirExists(t, filepath.Join(g1Cfg.Storages[0].Path, replicaPath))
require.DirExists(t, filepath.Join(g2Cfg.Storages[0].Path, replicaPath))
-
- requireNoDatabaseInfo(t, db, cmd)
+ require.False(t, repositoryExists(t, repo))
})
t.Run("one of gitalies is out of service", func(t *testing.T) {
@@ -233,27 +225,10 @@ func TestRemoveRepository_Exec(t *testing.T) {
require.NoDirExists(t, filepath.Join(g1Cfg.Storages[0].Path, replicaPath))
require.DirExists(t, filepath.Join(g2Cfg.Storages[0].Path, replicaPath))
-
- requireNoDatabaseInfo(t, db, cmd)
+ require.False(t, repositoryExists(t, repo))
})
}
-func requireNoDatabaseInfo(t *testing.T, db testdb.DB, cmd *removeRepository) {
- t.Helper()
- var repositoryRowExists bool
- require.NoError(t, db.QueryRow(
- `SELECT EXISTS(SELECT FROM repositories WHERE virtual_storage = $1 AND relative_path = $2)`,
- cmd.virtualStorage, cmd.relativePath,
- ).Scan(&repositoryRowExists))
- require.False(t, repositoryRowExists)
- var storageRowExists bool
- require.NoError(t, db.QueryRow(
- `SELECT EXISTS(SELECT FROM storage_repositories WHERE virtual_storage = $1 AND relative_path = $2)`,
- cmd.virtualStorage, cmd.relativePath,
- ).Scan(&storageRowExists))
- require.False(t, storageRowExists)
-}
-
func TestRemoveRepository_removeReplicationEvents(t *testing.T) {
t.Parallel()
const (