fix: stabilize development config and account settings

This commit is contained in:
2026-07-11 17:15:38 +08:00
parent d2cb6bbbc6
commit 7f2d5579ff
19 changed files with 607 additions and 392 deletions
+39
View File
@@ -0,0 +1,39 @@
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)
}
}