Skip to content

Commit e2fa7f2

Browse files
committed
Quiet a number of "gosec" warnings in tests
These are ignored by golangci-lint by default.
1 parent a5cd8f9 commit e2fa7f2

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

.golangci.next.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ linters:
2626
- wastedassign
2727

2828
issues:
29+
exclude-rules:
30+
# We call external linters when they are installed: Flake8, ShellCheck, etc.
31+
- linters: [gosec]
32+
path: '_test[.]go$'
33+
text: 'G204: Subprocess launched with variable'
34+
2935
# https://github.com/golangci/golangci-lint/issues/2239
3036
exclude-use-default: false
3137

internal/controller/postgrescluster/patroni_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,17 @@ func TestReconcilePatroniSwitchover(t *testing.T) {
539539
switch {
540540
case timelineCall:
541541
timelineCall = false
542-
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
542+
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
543543
case timelineCallNoLeader:
544-
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
544+
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
545545
case callError:
546546
return errors.New("boom")
547547
case callFails:
548-
stdout.Write([]byte("bang"))
548+
_, _ = stdout.Write([]byte("bang"))
549549
case failover:
550-
stdout.Write([]byte("failed over"))
550+
_, _ = stdout.Write([]byte("failed over"))
551551
default:
552-
stdout.Write([]byte("switched over"))
552+
_, _ = stdout.Write([]byte("switched over"))
553553
}
554554
return nil
555555
},

internal/controller/standalone_pgadmin/users_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {
112112

113113
// Simulate a v7 version of pgAdmin by setting stdout to "7" for
114114
// podexec call in reconcilePGAdminMajorVersion
115-
stdout.Write([]byte("7"))
115+
_, _ = stdout.Write([]byte("7"))
116116
return nil
117117
}
118118

@@ -147,7 +147,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {
147147

148148
// Simulate a v7 version of pgAdmin by setting stdout to "7" for
149149
// podexec call in reconcilePGAdminMajorVersion
150-
stdout.Write([]byte("7"))
150+
_, _ = stdout.Write([]byte("7"))
151151
return nil
152152
}
153153

@@ -182,7 +182,7 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {
182182

183183
// Simulate a v7 version of pgAdmin by setting stdout to "7" for
184184
// podexec call in reconcilePGAdminMajorVersion
185-
stdout.Write([]byte("7"))
185+
_, _ = stdout.Write([]byte("7"))
186186
return nil
187187
}
188188

@@ -197,7 +197,7 @@ func TestReconcilePGAdminMajorVersion(t *testing.T) {
197197
stdin io.Reader, stdout, stderr io.Writer, command ...string,
198198
) error {
199199
// Simulate the python call giving bad data (not a version int)
200-
stdout.Write([]byte("asdfjkl;"))
200+
_, _ = stdout.Write([]byte("asdfjkl;"))
201201
return nil
202202
}
203203

@@ -547,7 +547,7 @@ func TestWritePGAdminUsers(t *testing.T) {
547547
) error {
548548
calls++
549549

550-
stderr.Write([]byte("issue running setup.py update-user command"))
550+
_, _ = stderr.Write([]byte("issue running setup.py update-user command"))
551551

552552
return nil
553553
}
@@ -627,7 +627,7 @@ func TestWritePGAdminUsers(t *testing.T) {
627627
) error {
628628
calls++
629629

630-
stderr.Write([]byte("issue running setup.py add-user command"))
630+
_, _ = stderr.Write([]byte("issue running setup.py add-user command"))
631631

632632
return nil
633633
}
@@ -655,7 +655,7 @@ func TestWritePGAdminUsers(t *testing.T) {
655655
) error {
656656
calls++
657657

658-
stdout.Write([]byte("Invalid email address"))
658+
_, _ = stdout.Write([]byte("Invalid email address"))
659659

660660
return nil
661661
}
@@ -684,7 +684,7 @@ func TestWritePGAdminUsers(t *testing.T) {
684684
) error {
685685
calls++
686686

687-
stdout.Write([]byte("Password must be at least 6 characters long"))
687+
_, _ = stdout.Write([]byte("Password must be at least 6 characters long"))
688688

689689
return nil
690690
}

internal/patroni/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestExecutorGetTimeline(t *testing.T) {
243243
tl, actual := Executor(func(
244244
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
245245
) error {
246-
stderr.Write([]byte(`no luck`))
246+
_, _ = stderr.Write([]byte(`no luck`))
247247
return nil
248248
}).GetTimeline(context.Background())
249249

@@ -255,7 +255,7 @@ func TestExecutorGetTimeline(t *testing.T) {
255255
tl, actual := Executor(func(
256256
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
257257
) error {
258-
stdout.Write([]byte(`no luck`))
258+
_, _ = stdout.Write([]byte(`no luck`))
259259
return nil
260260
}).GetTimeline(context.Background())
261261

@@ -267,7 +267,7 @@ func TestExecutorGetTimeline(t *testing.T) {
267267
tl, actual := Executor(func(
268268
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
269269
) error {
270-
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
270+
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
271271
return nil
272272
}).GetTimeline(context.Background())
273273

@@ -279,7 +279,7 @@ func TestExecutorGetTimeline(t *testing.T) {
279279
tl, actual := Executor(func(
280280
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
281281
) error {
282-
stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
282+
_, _ = stdout.Write([]byte(`[{"Cluster": "hippo-ha", "Member": "hippo-instance1-67mc-0", "Host": "hippo-instance1-67mc-0.hippo-pods", "Role": "Leader", "State": "running", "TL": 4}, {"Cluster": "hippo-ha", "Member": "hippo-instance1-ltcf-0", "Host": "hippo-instance1-ltcf-0.hippo-pods", "Role": "Replica", "State": "running", "TL": 4, "Lag in MB": 0}]`))
283283
return nil
284284
}).GetTimeline(context.Background())
285285

0 commit comments

Comments
 (0)