77 "errors"
88 "fmt"
99 "net"
10- "os"
1110 "path/filepath"
1211 "reflect"
1312 "runtime"
@@ -78,8 +77,7 @@ func TestNewConnector(t *testing.T) {
7877 useConn (t , db )
7978 })
8079 t .Run ("Environ" , func (t * testing.T ) {
81- os .Setenv ("PGPASSFILE" , "/tmp/.pgpass" )
82- defer os .Unsetenv ("PGPASSFILE" )
80+ t .Setenv ("PGPASSFILE" , "/tmp/.pgpass" )
8381 c , err := NewConnector ("" )
8482 if err != nil {
8583 t .Fatal (err )
@@ -102,7 +100,7 @@ func TestNewConnector(t *testing.T) {
102100 t .Fatal (err )
103101 }
104102 want := fmt .Sprintf (
105- `map[client_encoding:UTF8 connect_timeout:20 datestyle:ISO, MDY dbname:pqgo host:localhost max_protocol_version:3.0 min_protocol_version:3.0 port:%d search_path:foo sslmode:disable sslsni:yes user:pqgo]` ,
103+ `map[application_name:pqgo client_encoding:UTF8 connect_timeout:20 datestyle:ISO, MDY dbname:pqgo host:localhost max_protocol_version:3.0 min_protocol_version:3.0 port:%d search_path:foo sslmode:disable sslsni:yes user:pqgo]` ,
106104 cfg .Port )
107105 if have := fmt .Sprintf ("%v" , c .cfg .tomap ()); have != want {
108106 t .Errorf ("\n have: %s\n want: %s" , have , want )
@@ -229,6 +227,7 @@ func TestRuntimeParameters(t *testing.T) {
229227 {"fallback_application_name=bar" , "application_name" , "bar" , "" , false },
230228 }
231229
230+ pqtest .Unsetenv (t , "PGAPPNAME" )
232231 for _ , tt := range tests {
233232 t .Run ("" , func (t * testing.T ) {
234233 if tt .skipPgbouncer {
@@ -905,11 +904,7 @@ func TestService(t *testing.T) {
905904 [svc5]
906905 ` ), h , ".pg_service.conf" )
907906
908- // pgbouncer sets PGPORT; not really used to just unset.
909- // TODO: might want to add pqtest.Clearenv() or the like.
910- t .Setenv ("PGPORT" , "" )
911- os .Unsetenv ("PGPORT" )
912-
907+ pqtest .Unsetenv (t , "PGPORT" )
913908 for _ , tt := range tests {
914909 t .Run ("" , func (t * testing.T ) {
915910 for k , v := range tt .env {
0 commit comments