MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / TestPostgresClientPasswordHandoff

Function TestPostgresClientPasswordHandoff

cmd/pad/postgres_client_test.go:61–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestPostgresClientPasswordHandoff(t *testing.T) {
62 t.Setenv("PGPASSWORD", "inherited")
63 t.Setenv("PGSERVICE", "")
64 if err := os.Unsetenv("PGSERVICE"); err != nil {
65 t.Fatal(err)
66 }
67 for _, name := range []string{"pg_dump", "psql"} {
68 cmd, err := postgresClient(name, "postgres://u:explicit@host/db", "--file", "backup.sql")
69 if err != nil {
70 t.Fatal(err)
71 }
72 if strings.Contains(strings.Join(cmd.Args, " "), "explicit") {
73 t.Fatal("password in process arguments")
74 }
75 if cmd.Args[len(cmd.Args)-2] != "--dbname" {
76 t.Fatal("libpq must receive an explicit database argument")
77 }
78 var password string
79 for _, value := range cmd.Env {
80 if strings.HasPrefix(value, "PGPASSWORD=") {
81 password = value
82 }
83 }
84 if password != "PGPASSWORD=explicit" {
85 t.Fatal("explicit password did not override environment")
86 }
87 }
88}
89
90// Use a separate source and destination database, not the suite's shared one.
91// Set PAD_TEST_POSTGRES_TOOLS_URL to a database with matching native clients.

Callers

nothing calls this directly

Calls 3

postgresClientFunction · 0.85
FatalMethod · 0.80
JoinMethod · 0.80

Tested by

no test coverage detected