From 19cb2f240e4b5e4b65df03267ef63b29a67d94a5 Mon Sep 17 00:00:00 2001 From: Alex Goth Date: Mon, 29 Jul 2024 15:43:46 +0200 Subject: [PATCH] fix: address PR comments --- e2e/diff/.gitignore | 1 - e2e/diff/no_schema_diff_test.go | 27 ++++++++++----------------- tools/migrate/main.go | 8 ++++---- 3 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 e2e/diff/.gitignore diff --git a/e2e/diff/.gitignore b/e2e/diff/.gitignore deleted file mode 100644 index 1559fcae5..000000000 --- a/e2e/diff/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tmp/** diff --git a/e2e/diff/no_schema_diff_test.go b/e2e/diff/no_schema_diff_test.go index f10e3fbdc..d66ef1465 100644 --- a/e2e/diff/no_schema_diff_test.go +++ b/e2e/diff/no_schema_diff_test.go @@ -14,42 +14,35 @@ import ( "github.com/openmeterio/openmeter/pkg/framework/entutils" ) -var PG_URL string +var pgUrl string func TestMain(m *testing.M) { - PG_URL = os.Getenv("POSTGRES_URL") + pgUrl = os.Getenv("POSTGRES_URL") os.Exit(m.Run()) } -const ( - DIR = "./tmp/" -) - func setup(t *testing.T) { - if PG_URL == "" { + t.Helper() + if pgUrl == "" { t.Skip("POSTGRES_URL not set") } } func TestNoSchemaDiffOnMigrate(t *testing.T) { setup(t) - driver, err := entutils.GetPGDriver(PG_URL) + driver, err := entutils.GetPGDriver(pgUrl) if err != nil { t.Fatalf("failed to get pg driver %s", err) } - // OpenMemDir doesn't work from inside dagger - // dir := migrate.OpenMemDir("migrations") - err = os.RemoveAll(DIR) + tmpDirPath, err := os.MkdirTemp("", "migrate") if err != nil { - t.Fatalf("failed to remove dir %s", err) + t.Fatalf("failed to create temp dir %s", err) } - err = os.MkdirAll(DIR, os.ModePerm) - if err != nil { - t.Fatalf("failed to create dir %s", err) - } - dir, err := migrate.NewLocalDir(DIR) + defer os.RemoveAll(tmpDirPath) + + dir, err := migrate.NewLocalDir(tmpDirPath) if err != nil { t.Fatalf("failed to open local dir %s", err) } diff --git a/tools/migrate/main.go b/tools/migrate/main.go index 2fa0a1a3a..5dedb5df2 100644 --- a/tools/migrate/main.go +++ b/tools/migrate/main.go @@ -10,15 +10,15 @@ import ( ) func main() { - PG_URL := os.Getenv("POSTGRES_URL") - if PG_URL == "" { - PG_URL = "postgres://postgres:postgres@localhost:5432/postgres" + pgUrl := os.Getenv("POSTGRES_URL") + if pgUrl == "" { + pgUrl = "postgres://postgres:postgres@localhost:5432/postgres" } logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) slog.SetDefault(logger) - driver, err := entutils.GetPGDriver(PG_URL) + driver, err := entutils.GetPGDriver(pgUrl) if err != nil { logger.Error("failed to get pg driver", slog.Any("error", err)) os.Exit(1)