Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix permissions for tests without extension
Browse files Browse the repository at this point in the history
  • Loading branch information
cevian committed Oct 3, 2020
1 parent c012806 commit 3a5c92e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 6 additions & 4 deletions pkg/internal/testhelpers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,17 @@ func StartPGContainerWithImage(ctx context.Context, image string, testDataDir st
},
SkipReaper: false, /* switch to true not to kill docker container */
}
req.Cmd = []string{
"-c", "shared_preload_libraries=timescaledb",
"-c", "max_connections=100",
}

if withExtension {
req.Cmd = []string{
"-c", "shared_preload_libraries=timescaledb",
req.Cmd = append(req.Cmd,
"-c", "local_preload_libraries=pgextwlist",
"-c", "max_connections=100",
//timescale_prometheus_extra included for upgrade tests with old extension name
"-c", "extwlist.extensions=promscale,timescaledb,timescale_prometheus_extra",
}
)
}

req.BindMounts = make(map[string]string)
Expand Down
12 changes: 9 additions & 3 deletions pkg/pgmodel/end_to_end_tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestMain(m *testing.M) {

func withDB(t testing.TB, DBName string, f func(db *pgxpool.Pool, t testing.TB)) {
testhelpers.WithDB(t, DBName, testhelpers.NoSuperuser, func(_ *pgxpool.Pool, t testing.TB, connectURL string) {
performMigrate(t, connectURL)
performMigrate(t, connectURL, testhelpers.PgConnectURL(DBName, testhelpers.Superuser))

// need to get a new pool after the Migrate to catch any GUC changes made during Migrate
db, err := pgxpool.Connect(context.Background(), connectURL)
Expand All @@ -107,9 +107,15 @@ func withDB(t testing.TB, DBName string, f func(db *pgxpool.Pool, t testing.TB))
})
}

func performMigrate(t testing.TB, connectURL string) {
func performMigrate(t testing.TB, connectURL string, superConnectURL string) {
if *useTimescaleDB {
err := pgmodel.MigrateTimescaleDBExtension(connectURL)
migrateURL := connectURL
if !*useExtension {
//The docker image without an extension does not have pgextwlist
//Thus, you have to use the superuser to install TimescaleDB
migrateURL = superConnectURL
}
err := pgmodel.MigrateTimescaleDBExtension(migrateURL)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/pgmodel/end_to_end_tests/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ func TestMigrateTwice(t *testing.T) {
t.Skip("skipping integration test")
}
testhelpers.WithDB(t, *testDatabase, testhelpers.NoSuperuser, func(db *pgxpool.Pool, t testing.TB, connectURL string) {
performMigrate(t, connectURL)
performMigrate(t, connectURL, testhelpers.PgConnectURL(*testDatabase, testhelpers.Superuser))
if *useExtension && !pgmodel.ExtensionIsInstalled {
t.Errorf("extension is not installed, expected it to be installed")
}

//reset the flag to make sure it's set correctly again.
pgmodel.ExtensionIsInstalled = false

performMigrate(t, connectURL)
performMigrate(t, connectURL, testhelpers.PgConnectURL(*testDatabase, testhelpers.Superuser))
if *useExtension && !pgmodel.ExtensionIsInstalled {
t.Errorf("extension is not installed, expected it to be installed")
}
Expand Down

0 comments on commit 3a5c92e

Please sign in to comment.