* HH-448 enforce PostgreSQL E2E gate * HH-448 fail CI when concurrency test is missing --------- Co-authored-by: Rogee <rogee@ipao.vip>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package database
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMigrationCommandsRejectBlankPath(t *testing.T) {
|
|
tests := map[string]func() error{
|
|
"run": func() error { return RunMigrations("invalid-url", " \t") },
|
|
"steps": func() error { return MigrateSteps("invalid-url", " \t", 1) },
|
|
"rollback": func() error { return RollbackMigrations("invalid-url", " \t") },
|
|
"force": func() error { return ForceVersion("invalid-url", " \t", 1) },
|
|
"version": func() error {
|
|
_, _, err := CurrentVersion("invalid-url", " \t")
|
|
return err
|
|
},
|
|
}
|
|
|
|
for name, run := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
require.EqualError(t, run(), "migration path must not be empty")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestWithSanitizedPQEnvironment(t *testing.T) {
|
|
t.Setenv("PGSERVICE", "local-service")
|
|
t.Setenv("PGSERVICEFILE", "/tmp/pg_service.conf")
|
|
t.Setenv("PGREALM", "local-realm")
|
|
|
|
err := withSanitizedPQEnvironment(func() error {
|
|
for _, key := range []string{"PGSERVICE", "PGSERVICEFILE", "PGREALM"} {
|
|
_, exists := os.LookupEnv(key)
|
|
require.False(t, exists, "%s should be unset during migration", key)
|
|
}
|
|
return nil
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, "local-service", os.Getenv("PGSERVICE"))
|
|
require.Equal(t, "/tmp/pg_service.conf", os.Getenv("PGSERVICEFILE"))
|
|
require.Equal(t, "local-realm", os.Getenv("PGREALM"))
|
|
}
|
|
|
|
func TestSanitizePostgresEnvironment(t *testing.T) {
|
|
t.Setenv("PGSERVICE", "local-service")
|
|
t.Setenv("PGSERVICEFILE", "/tmp/pg_service.conf")
|
|
t.Setenv("PGREALM", "local-realm")
|
|
|
|
SanitizePostgresEnvironment()
|
|
|
|
for _, key := range unsupportedPQEnvironmentKeys {
|
|
_, exists := os.LookupEnv(key)
|
|
require.False(t, exists, "%s should be removed at application startup", key)
|
|
}
|
|
}
|