Skip to content

File tree

12 files changed

+32
-32
lines changed

12 files changed

+32
-32
lines changed

internal/patroni/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ func TestPGBackRestCreateReplicaCommand(t *testing.T) {
794794
file := filepath.Join(dir, "command.sh")
795795
assert.NilError(t, os.WriteFile(file, []byte(command), 0o600))
796796

797-
cmd := exec.Command(shellcheck, "--enable=all", "--shell=sh", file)
797+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", "--shell=sh", file)
798798
output, err := cmd.CombinedOutput()
799799
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
800800
}
@@ -816,7 +816,7 @@ func TestPGBackRestCreateReplicaCommand(t *testing.T) {
816816
file := filepath.Join(dir, "script.bash")
817817
assert.NilError(t, os.WriteFile(file, []byte(script), 0o600))
818818

819-
cmd := exec.Command(shellcheck, "--enable=all", file)
819+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
820820
output, err := cmd.CombinedOutput()
821821
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
822822
}

internal/pgadmin/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestStartupCommand(t *testing.T) {
7777
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
7878

7979
// Expect shellcheck to be happy.
80-
cmd := exec.Command(shellcheck, "--enable=all", file)
80+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
8181
output, err := cmd.CombinedOutput()
8282
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
8383
})
@@ -94,7 +94,7 @@ func TestStartupCommand(t *testing.T) {
9494
// Expect flake8 to be happy. Ignore "E401 multiple imports on one line"
9595
// in addition to the defaults. The file contents appear in PodSpec, so
9696
// allow lines longer than the default to save some vertical space.
97-
cmd := exec.Command(flake8, "--extend-ignore=E401", "--max-line-length=99", file)
97+
cmd := exec.CommandContext(t.Context(), flake8, "--extend-ignore=E401", "--max-line-length=99", file)
9898
output, err := cmd.CombinedOutput()
9999
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
100100
})

internal/pgadmin/users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ with create_app().app_context():
180180

181181
// Expect flake8 to be happy. Ignore "E402 module level import not
182182
// at top of file" in addition to the defaults.
183-
cmd := exec.Command(flake8, "--extend-ignore=E402", file)
183+
cmd := exec.CommandContext(t.Context(), flake8, "--extend-ignore=E402", file)
184184
output, err := cmd.CombinedOutput()
185185
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
186186

internal/pgbackrest/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func TestReloadCommand(t *testing.T) {
580580
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
581581

582582
// Expect shellcheck to be happy.
583-
cmd := exec.Command(shellcheck, "--enable=all", file)
583+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
584584
output, err := cmd.CombinedOutput()
585585
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
586586
}
@@ -606,7 +606,7 @@ func TestRestoreCommand(t *testing.T) {
606606
file := filepath.Join(dir, "script.bash")
607607
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
608608

609-
cmd := exec.Command(shellcheck, "--enable=all", file)
609+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
610610
output, err := cmd.CombinedOutput()
611611
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
612612
}
@@ -645,7 +645,7 @@ func TestDedicatedSnapshotVolumeRestoreCommand(t *testing.T) {
645645
file := filepath.Join(dir, "script.bash")
646646
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
647647

648-
cmd := exec.Command(shellcheck, "--enable=all", file)
648+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
649649
output, err := cmd.CombinedOutput()
650650
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
651651
}

internal/pgbackrest/pgbackrest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fi
9292
assert.NilError(t, os.WriteFile(file, []byte(shellCheckScript), 0o600))
9393

9494
// Expect shellcheck to be happy.
95-
cmd := exec.Command(shellcheck, "--enable=all", file)
95+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
9696
output, err := cmd.CombinedOutput()
9797
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
9898
}

internal/pgbouncer/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func TestReloadCommand(t *testing.T) {
216216
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
217217

218218
// Expect shellcheck to be happy.
219-
cmd := exec.Command(shellcheck, "--enable=all", file)
219+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
220220
output, err := cmd.CombinedOutput()
221221
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
222222
}

internal/pki/encoding_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestCertificateTextMarshaling(t *testing.T) {
8181
assert.NilError(t, os.WriteFile(certFile, certBytes, 0o600))
8282

8383
// The "openssl x509" command parses X.509 certificates.
84-
cmd := exec.Command(openssl, "x509",
84+
cmd := exec.CommandContext(t.Context(), openssl, "x509",
8585
"-in", certFile, "-inform", "PEM", "-noout", "-text")
8686

8787
output, err := cmd.CombinedOutput()
@@ -153,7 +153,7 @@ func TestPrivateKeyTextMarshaling(t *testing.T) {
153153
assert.NilError(t, os.WriteFile(keyFile, keyBytes, 0o600))
154154

155155
// The "openssl pkey" command processes public and private keys.
156-
cmd := exec.Command(openssl, "pkey",
156+
cmd := exec.CommandContext(t.Context(), openssl, "pkey",
157157
"-in", keyFile, "-inform", "PEM", "-noout", "-text")
158158

159159
output, err := cmd.CombinedOutput()
@@ -164,12 +164,12 @@ func TestPrivateKeyTextMarshaling(t *testing.T) {
164164
"expected valid private key, got:\n%s", output)
165165

166166
t.Run("Check", func(t *testing.T) {
167-
output, _ := exec.Command(openssl, "pkey", "-help").CombinedOutput()
167+
output, _ := exec.CommandContext(t.Context(), openssl, "pkey", "-help").CombinedOutput()
168168
if !strings.Contains(string(output), "-check") {
169169
t.Skip(`requires "-check" flag`)
170170
}
171171

172-
cmd := exec.Command(openssl, "pkey",
172+
cmd := exec.CommandContext(t.Context(), openssl, "pkey",
173173
"-check", "-in", keyFile, "-inform", "PEM", "-noout", "-text")
174174

175175
output, err := cmd.CombinedOutput()

internal/pki/pki_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func basicOpenSSLVerify(t *testing.T, openssl string, root, leaf Certificate) {
439439
verify := func(t testing.TB, args ...string) {
440440
t.Helper()
441441
// #nosec G204 -- args from this test
442-
cmd := exec.Command(openssl, append([]string{"verify"}, args...)...)
442+
cmd := exec.CommandContext(t.Context(), openssl, append([]string{"verify"}, args...)...)
443443

444444
output, err := cmd.CombinedOutput()
445445
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
@@ -476,7 +476,7 @@ func basicOpenSSLVerify(t *testing.T, openssl string, root, leaf Certificate) {
476476
}
477477

478478
func strictOpenSSLVerify(t *testing.T, openssl string, root, leaf Certificate) {
479-
output, _ := exec.Command(openssl, "verify", "-help").CombinedOutput()
479+
output, _ := exec.CommandContext(t.Context(), openssl, "verify", "-help").CombinedOutput()
480480
if !strings.Contains(string(output), "-x509_strict") {
481481
t.Skip(`requires "-x509_strict" flag`)
482482
}
@@ -487,7 +487,7 @@ func strictOpenSSLVerify(t *testing.T, openssl string, root, leaf Certificate) {
487487
verify := func(t testing.TB, args ...string) {
488488
t.Helper()
489489
// #nosec G204 -- args from this test
490-
cmd := exec.Command(openssl, append([]string{"verify",
490+
cmd := exec.CommandContext(t.Context(), openssl, append([]string{"verify",
491491
// Do not use the default trusted CAs.
492492
"-no-CAfile", "-no-CApath",
493493
// Disable "non-compliant workarounds for broken certificates".

internal/postgres/config_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestWALDirectory(t *testing.T) {
5252

5353
func TestBashHalt(t *testing.T) {
5454
t.Run("NoPipeline", func(t *testing.T) {
55-
cmd := exec.Command("bash")
55+
cmd := exec.CommandContext(t.Context(), "bash")
5656
cmd.Args = append(cmd.Args, "-c", "--", bashHalt+`; halt ab cd e`)
5757

5858
var exit *exec.ExitError
@@ -64,7 +64,7 @@ func TestBashHalt(t *testing.T) {
6464
})
6565

6666
t.Run("PipelineZeroStatus", func(t *testing.T) {
67-
cmd := exec.Command("bash")
67+
cmd := exec.CommandContext(t.Context(), "bash")
6868
cmd.Args = append(cmd.Args, "-c", "--", bashHalt+`; true && halt message`)
6969

7070
var exit *exec.ExitError
@@ -76,7 +76,7 @@ func TestBashHalt(t *testing.T) {
7676
})
7777

7878
t.Run("PipelineNonZeroStatus", func(t *testing.T) {
79-
cmd := exec.Command("bash")
79+
cmd := exec.CommandContext(t.Context(), "bash")
8080
cmd.Args = append(cmd.Args, "-c", "--", bashHalt+`; (exit 99) || halt $'multi\nline'`)
8181

8282
var exit *exec.ExitError
@@ -88,7 +88,7 @@ func TestBashHalt(t *testing.T) {
8888
})
8989

9090
t.Run("Subshell", func(t *testing.T) {
91-
cmd := exec.Command("bash")
91+
cmd := exec.CommandContext(t.Context(), "bash")
9292
cmd.Args = append(cmd.Args, "-c", "--", bashHalt+`; (halt 'err') || echo 'after'`)
9393

9494
stderr := new(bytes.Buffer)
@@ -104,7 +104,7 @@ func TestBashHalt(t *testing.T) {
104104

105105
func TestBashPermissions(t *testing.T) {
106106
// macOS `stat` takes different arguments than BusyBox and GNU coreutils.
107-
if output, err := exec.Command("stat", "--help").CombinedOutput(); err != nil {
107+
if output, err := exec.CommandContext(t.Context(), "stat", "--help").CombinedOutput(); err != nil {
108108
t.Skip(`requires "stat" executable`)
109109
} else if !strings.Contains(string(output), "%A") {
110110
t.Skip(`requires "stat" with access format sequence`)
@@ -116,7 +116,7 @@ func TestBashPermissions(t *testing.T) {
116116
assert.NilError(t, os.WriteFile(filepath.Join(dir, "sub", "fn"), nil, 0o624)) // #nosec G306 OK permissions for a temp dir in a test
117117
assert.NilError(t, os.Chmod(filepath.Join(dir, "sub", "fn"), 0o624))
118118

119-
cmd := exec.Command("bash")
119+
cmd := exec.CommandContext(t.Context(), "bash")
120120
cmd.Args = append(cmd.Args, "-c", "--",
121121
bashPermissions+`; permissions "$@"`, "-",
122122
filepath.Join(dir, "sub", "fn"))
@@ -131,7 +131,7 @@ func TestBashPermissions(t *testing.T) {
131131

132132
func TestBashRecreateDirectory(t *testing.T) {
133133
// macOS `stat` takes different arguments than BusyBox and GNU coreutils.
134-
if output, err := exec.Command("stat", "--help").CombinedOutput(); err != nil {
134+
if output, err := exec.CommandContext(t.Context(), "stat", "--help").CombinedOutput(); err != nil {
135135
t.Skip(`requires "stat" executable`)
136136
} else if !strings.Contains(string(output), "%a") {
137137
t.Skip(`requires "stat" with access format sequence`)
@@ -143,7 +143,7 @@ func TestBashRecreateDirectory(t *testing.T) {
143143
assert.NilError(t, os.WriteFile(filepath.Join(dir, "d", "file"), nil, 0o644)) // #nosec G306 OK permissions for a temp dir in a test
144144

145145
stat := func(args ...string) string {
146-
cmd := exec.Command("stat", "-c", "%i %#a %N")
146+
cmd := exec.CommandContext(t.Context(), "stat", "-c", "%i %#a %N")
147147
cmd.Args = append(cmd.Args, args...)
148148
out, err := cmd.CombinedOutput()
149149

@@ -160,7 +160,7 @@ func TestBashRecreateDirectory(t *testing.T) {
160160
filepath.Join(dir, "d", "file"),
161161
)
162162

163-
cmd := exec.Command("bash")
163+
cmd := exec.CommandContext(t.Context(), "bash")
164164
cmd.Args = append(cmd.Args, "-ceu", "--",
165165
bashRecreateDirectory+` recreate "$@"`, "-",
166166
filepath.Join(dir, "d"), "0740")
@@ -199,15 +199,15 @@ func TestBashRecreateDirectory(t *testing.T) {
199199

200200
func TestBashSafeLink(t *testing.T) {
201201
// macOS `mv` takes different arguments than GNU coreutils.
202-
if output, err := exec.Command("mv", "--help").CombinedOutput(); err != nil {
202+
if output, err := exec.CommandContext(t.Context(), "mv", "--help").CombinedOutput(); err != nil {
203203
t.Skip(`requires "mv" executable`)
204204
} else if !strings.Contains(string(output), "no-target-directory") {
205205
t.Skip(`requires "mv" that overwrites a directory symlink`)
206206
}
207207

208208
// execute calls the bash function with args.
209209
execute := func(args ...string) (string, error) {
210-
cmd := exec.Command("bash")
210+
cmd := exec.CommandContext(t.Context(), "bash")
211211
cmd.Args = append(cmd.Args, "-ceu", "--", bashSafeLink+`safelink "$@"`, "-")
212212
cmd.Args = append(cmd.Args, args...)
213213
output, err := cmd.CombinedOutput()
@@ -474,7 +474,7 @@ func TestStartupCommand(t *testing.T) {
474474
assert.NilError(t, os.WriteFile(file, []byte(script), 0o600))
475475

476476
// Expect shellcheck to be happy.
477-
cmd := exec.Command(shellcheck, "--enable=all", file)
477+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
478478
output, err := cmd.CombinedOutput()
479479
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
480480

internal/postgres/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ done <<< "${databases}"
184184
assert.NilError(t, os.WriteFile(file, []byte(script), 0o600))
185185

186186
// Expect shellcheck to be happy.
187-
cmd := exec.Command(shellcheck, "--enable=all", file)
187+
cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
188188
output, err := cmd.CombinedOutput()
189189
assert.NilError(t, err, "%q\n%s", cmd.Args, output)
190190

0 commit comments

Comments
 (0)