Skip to content

Commit

Permalink
Quiet a number of "gosec" warnings in tests
Browse files Browse the repository at this point in the history
These are ignored by golangci-lint by default.
  • Loading branch information
cbandy committed Nov 6, 2024
1 parent a5cd8f9 commit e2fa7f2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .golangci.next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ linters:
- wastedassign

issues:
exclude-rules:
# We call external linters when they are installed: Flake8, ShellCheck, etc.
- linters: [gosec]
path: '_test[.]go$'
text: 'G204: Subprocess launched with variable'

# https://github.com/golangci/golangci-lint/issues/2239
exclude-use-default: false

Expand Down
10 changes: 5 additions & 5 deletions internal/controller/postgrescluster/patroni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,17 @@ func TestReconcilePatroniSwitchover(t *testing.T) {
switch {
case timelineCall:
timelineCall = false
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}]`))
_, _ = 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}]`))
case timelineCallNoLeader:
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}]`))
_, _ = 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}]`))
case callError:
return errors.New("boom")
case callFails:
stdout.Write([]byte("bang"))
_, _ = stdout.Write([]byte("bang"))
case failover:
stdout.Write([]byte("failed over"))
_, _ = stdout.Write([]byte("failed over"))
default:
stdout.Write([]byte("switched over"))
_, _ = stdout.Write([]byte("switched over"))
}
return nil
},
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/standalone_pgadmin/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestReconcilePGAdminUsers(t *testing.T) {

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

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

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

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

// Simulate a v7 version of pgAdmin by setting stdout to "7" for
// podexec call in reconcilePGAdminMajorVersion
stdout.Write([]byte("7"))
_, _ = stdout.Write([]byte("7"))
return nil
}

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

Expand Down Expand Up @@ -547,7 +547,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

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

return nil
}
Expand Down Expand Up @@ -627,7 +627,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

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

return nil
}
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

stdout.Write([]byte("Invalid email address"))
_, _ = stdout.Write([]byte("Invalid email address"))

return nil
}
Expand Down Expand Up @@ -684,7 +684,7 @@ func TestWritePGAdminUsers(t *testing.T) {
) error {
calls++

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

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/patroni/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
stderr.Write([]byte(`no luck`))
_, _ = stderr.Write([]byte(`no luck`))
return nil
}).GetTimeline(context.Background())

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

Expand All @@ -267,7 +267,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
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}]`))
_, _ = 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}]`))
return nil
}).GetTimeline(context.Background())

Expand All @@ -279,7 +279,7 @@ func TestExecutorGetTimeline(t *testing.T) {
tl, actual := Executor(func(
_ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
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}]`))
_, _ = 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}]`))
return nil
}).GetTimeline(context.Background())

Expand Down

0 comments on commit e2fa7f2

Please sign in to comment.