diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-13 11:11:35 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-16 09:42:52 +0300 |
commit | 0f3649eb77862db138a8ab7c56685fadd61a114b (patch) | |
tree | 5cfb476d7ecb316ff81f4432b6c21de01b68f429 /cmd | |
parent | 2fe1dab8d0d22d7e5563c4214ffa8186a953e01a (diff) |
glsql: Move test database implementation into testdb package
The glsql package hosts both the implementation used to connect to a
"normal" production database as well as the logic to connect to a test
database. Mixing production and test code like this is bad practice
though.
Move test-related functions into the "testdb" package to fix this. This
change requires the glsql tests to use a separate package to break a
cyclic dependency between the "glsql" and "testdb" package. And
furthermore, the linter kicks in after this move and (legitly) complains
about missing error checks and closes for rows.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/praefect/main_test.go | 6 | ||||
-rw-r--r-- | cmd/praefect/subcmd_accept_dataloss_test.go | 4 | ||||
-rw-r--r-- | cmd/praefect/subcmd_dataloss_test.go | 3 | ||||
-rw-r--r-- | cmd/praefect/subcmd_list_untracked_repositories_test.go | 6 | ||||
-rw-r--r-- | cmd/praefect/subcmd_metadata_test.go | 3 | ||||
-rw-r--r-- | cmd/praefect/subcmd_remove_repository_test.go | 10 | ||||
-rw-r--r-- | cmd/praefect/subcmd_set_replication_factor_test.go | 4 | ||||
-rw-r--r-- | cmd/praefect/subcmd_track_repository_test.go | 6 |
8 files changed, 20 insertions, 22 deletions
diff --git a/cmd/praefect/main_test.go b/cmd/praefect/main_test.go index 25a615876..82a7e0ee0 100644 --- a/cmd/praefect/main_test.go +++ b/cmd/praefect/main_test.go @@ -13,8 +13,8 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/bootstrap/starter" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" ) func TestMain(m *testing.M) { @@ -190,8 +190,8 @@ func (m *mockRegisterer) Gather() ([]*dto.MetricFamily, error) { func TestExcludeDatabaseMetricsFromDefaultMetrics(t *testing.T) { t.Parallel() - db := glsql.NewDB(t) - dbConf := glsql.GetDBConfig(t, db.Name) + db := testdb.NewDB(t) + dbConf := testdb.GetDBConfig(t, db.Name) conf := config.Config{ SocketPath: testhelper.GetTemporaryGitalySocketFileName(t), diff --git a/cmd/praefect/subcmd_accept_dataloss_test.go b/cmd/praefect/subcmd_accept_dataloss_test.go index ef80069b7..348cb6c27 100644 --- a/cmd/praefect/subcmd_accept_dataloss_test.go +++ b/cmd/praefect/subcmd_accept_dataloss_test.go @@ -7,9 +7,9 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) @@ -35,7 +35,7 @@ func TestAcceptDatalossSubcommand(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - db := glsql.NewDB(t) + db := testdb.NewDB(t) rs := datastore.NewPostgresRepositoryStore(db, conf.StorageNames()) startingGenerations := map[string]int{st1: 1, st2: 0, st3: datastore.GenerationUnknown} diff --git a/cmd/praefect/subcmd_dataloss_test.go b/cmd/praefect/subcmd_dataloss_test.go index b4fe18eb6..0e73e829f 100644 --- a/cmd/praefect/subcmd_dataloss_test.go +++ b/cmd/praefect/subcmd_dataloss_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" @@ -42,7 +41,7 @@ func TestDatalossSubcommand(t *testing.T) { }, } - tx := glsql.NewDB(t).Begin(t) + tx := testdb.NewDB(t).Begin(t) defer tx.Rollback(t) ctx, cancel := testhelper.Context() diff --git a/cmd/praefect/subcmd_list_untracked_repositories_test.go b/cmd/praefect/subcmd_list_untracked_repositories_test.go index 527a3219c..9a714c388 100644 --- a/cmd/praefect/subcmd_list_untracked_repositories_test.go +++ b/cmd/praefect/subcmd_list_untracked_repositories_test.go @@ -17,9 +17,9 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/setup" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) @@ -64,10 +64,10 @@ func TestListUntrackedRepositories_Exec(t *testing.T) { g1Addr := testserver.RunGitalyServer(t, g1Cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) g2Addr := testserver.RunGitalyServer(t, g2Cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) - db := glsql.NewDB(t) + db := testdb.NewDB(t) var database string require.NoError(t, db.QueryRow(`SELECT current_database()`).Scan(&database)) - dbConf := glsql.GetDBConfig(t, database) + dbConf := testdb.GetDBConfig(t, database) conf := config.Config{ SocketPath: testhelper.GetTemporaryGitalySocketFileName(t), diff --git a/cmd/praefect/subcmd_metadata_test.go b/cmd/praefect/subcmd_metadata_test.go index dc5cd2b60..24c859fe2 100644 --- a/cmd/praefect/subcmd_metadata_test.go +++ b/cmd/praefect/subcmd_metadata_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" @@ -23,7 +22,7 @@ func TestMetadataSubcommand(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - tx := glsql.NewDB(t).Begin(t) + tx := testdb.NewDB(t).Begin(t) defer tx.Rollback(t) testdb.SetHealthyNodes(t, ctx, tx, map[string]map[string][]string{ diff --git a/cmd/praefect/subcmd_remove_repository_test.go b/cmd/praefect/subcmd_remove_repository_test.go index bf2ece389..30c77a92c 100644 --- a/cmd/praefect/subcmd_remove_repository_test.go +++ b/cmd/praefect/subcmd_remove_repository_test.go @@ -20,9 +20,9 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) @@ -75,8 +75,8 @@ func TestRemoveRepository_Exec(t *testing.T) { g1Addr := testserver.RunGitalyServer(t, g1Cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) g2Srv := testserver.StartGitalyServer(t, g2Cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) - db := glsql.NewDB(t) - dbConf := glsql.GetDBConfig(t, db.Name) + db := testdb.NewDB(t) + dbConf := testdb.GetDBConfig(t, db.Name) conf := config.Config{ SocketPath: testhelper.GetTemporaryGitalySocketFileName(t), @@ -233,7 +233,7 @@ func TestRemoveRepository_Exec(t *testing.T) { <-stopped } -func requireNoDatabaseInfo(t *testing.T, db glsql.DB, cmd *removeRepository) { +func requireNoDatabaseInfo(t *testing.T, db testdb.DB, cmd *removeRepository) { t.Helper() var repositoryRowExists bool require.NoError(t, db.QueryRow( @@ -259,7 +259,7 @@ func TestRemoveRepository_removeReplicationEvents(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - db := glsql.NewDB(t) + db := testdb.NewDB(t) queue := datastore.NewPostgresReplicationEventQueue(db) diff --git a/cmd/praefect/subcmd_set_replication_factor_test.go b/cmd/praefect/subcmd_set_replication_factor_test.go index 6e0d0e3e0..b26daeeb0 100644 --- a/cmd/praefect/subcmd_set_replication_factor_test.go +++ b/cmd/praefect/subcmd_set_replication_factor_test.go @@ -8,16 +8,16 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) func TestSetReplicationFactorSubcommand(t *testing.T) { t.Parallel() - db := glsql.NewDB(t) + db := testdb.NewDB(t) for _, tc := range []struct { desc string diff --git a/cmd/praefect/subcmd_track_repository_test.go b/cmd/praefect/subcmd_track_repository_test.go index ed55c1ce7..dd1e6fe43 100644 --- a/cmd/praefect/subcmd_track_repository_test.go +++ b/cmd/praefect/subcmd_track_repository_test.go @@ -15,12 +15,12 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" - "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testdb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) @@ -86,8 +86,8 @@ func TestAddRepository_Exec(t *testing.T) { g1Addr := g1Srv.Address() - db := glsql.NewDB(t) - dbConf := glsql.GetDBConfig(t, db.Name) + db := testdb.NewDB(t) + dbConf := testdb.GetDBConfig(t, db.Name) virtualStorageName := "praefect" conf := config.Config{ |