diff --git a/.golangci.next.yaml b/.golangci.next.yaml index 49c1c6005..6b76d7b1d 100644 --- a/.golangci.next.yaml +++ b/.golangci.next.yaml @@ -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 diff --git a/internal/controller/postgrescluster/patroni_test.go b/internal/controller/postgrescluster/patroni_test.go index b2a457685..4f1bbba0b 100644 --- a/internal/controller/postgrescluster/patroni_test.go +++ b/internal/controller/postgrescluster/patroni_test.go @@ -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 }, diff --git a/internal/controller/standalone_pgadmin/users_test.go b/internal/controller/standalone_pgadmin/users_test.go index 409fcea70..4a600424b 100644 --- a/internal/controller/standalone_pgadmin/users_test.go +++ b/internal/controller/standalone_pgadmin/users_test.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/internal/patroni/api_test.go b/internal/patroni/api_test.go index 1603d2fc7..4eb561ad2 100644 --- a/internal/patroni/api_test.go +++ b/internal/patroni/api_test.go @@ -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()) @@ -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()) @@ -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()) @@ -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())