Skip to content

Commit acf06cf

Browse files
committed
Clear PG* envvars in tests that can be affected by them
1 parent b79032a commit acf06cf

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

pgconn/config_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ func getDefaultUser(t *testing.T) string {
5353
return osUserName
5454
}
5555

56+
var pgEnvvars = []string{"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "PGAPPNAME", "PGSSLMODE", "PGCONNECT_TIMEOUT", "PGSSLSNI", "PGTZ", "PGOPTIONS"}
57+
58+
func clearPgEnvvars(t *testing.T) {
59+
for _, env := range pgEnvvars {
60+
t.Setenv(env, "")
61+
}
62+
}
63+
5664
func TestParseConfig(t *testing.T) {
5765
skipOnWindows(t)
58-
t.Parallel()
66+
clearPgEnvvars(t)
5967

6068
config, err := pgconn.ParseConfig("")
6169
require.NoError(t, err)
@@ -933,8 +941,6 @@ func TestParseConfigEnvLibpq(t *testing.T) {
933941
}
934942
}
935943

936-
pgEnvvars := []string{"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "PGAPPNAME", "PGSSLMODE", "PGCONNECT_TIMEOUT", "PGSSLSNI", "PGTZ", "PGOPTIONS"}
937-
938944
tests := []struct {
939945
name string
940946
envvars map[string]string
@@ -1021,7 +1027,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
10211027

10221028
func TestParseConfigReadsPgPassfile(t *testing.T) {
10231029
skipOnWindows(t)
1024-
t.Parallel()
1030+
clearPgEnvvars(t)
10251031

10261032
tfName := filepath.Join(t.TempDir(), "config")
10271033
err := os.WriteFile(tfName, []byte("test1:5432:curlydb:curly:nyuknyuknyuk"), 0o600)
@@ -1046,7 +1052,7 @@ func TestParseConfigReadsPgPassfile(t *testing.T) {
10461052

10471053
func TestParseConfigReadsPgServiceFile(t *testing.T) {
10481054
skipOnWindows(t)
1049-
t.Parallel()
1055+
clearPgEnvvars(t)
10501056

10511057
tfName := filepath.Join(t.TempDir(), "config")
10521058

0 commit comments

Comments
 (0)