40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package database
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|