diff --git a/.golangci.yml b/.golangci.yml index deaca715..4014bb46 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,6 @@ linters: - scopelint - unconvert - unparam - - interfacer - nakedret - gocyclo - dupl diff --git a/pkg/test/utils/kubernetes.go b/pkg/test/utils/kubernetes.go index 70f5f555..daed078e 100644 --- a/pkg/test/utils/kubernetes.go +++ b/pkg/test/utils/kubernetes.go @@ -970,7 +970,7 @@ func GetArgs(ctx context.Context, cmd harness.Command, namespace string, env map // RunCommand runs a command with args. // args gets split on spaces (respecting quoted strings). // if the command is run in the background a reference to the process is returned for later cleanup -func RunCommand(ctx context.Context, namespace string, cmd harness.Command, cwd string, stdout io.Writer, stderr io.Writer, timeout int) (*exec.Cmd, error) { +func RunCommand(ctx context.Context, namespace string, cmd harness.Command, cwd string, stdout io.Writer, stderr io.Writer, logger Logger, timeout int) (*exec.Cmd, error) { actualDir, err := os.Getwd() if err != nil { return nil, err @@ -1008,6 +1008,8 @@ func RunCommand(ctx context.Context, namespace string, cmd harness.Command, cwd return nil, err } + logger.Logf("running command: %v", builtCmd.Args) + builtCmd.Dir = cwd builtCmd.Stdout = stdout builtCmd.Stderr = stderr @@ -1054,7 +1056,7 @@ func RunCommands(logger Logger, namespace string, commands []harness.Command, wo for _, cmd := range commands { logger.Logf("running command: %q", cmd.Command) - bg, err := RunCommand(context.Background(), namespace, cmd, workdir, logger, logger, timeout) + bg, err := RunCommand(context.Background(), namespace, cmd, workdir, logger, logger, logger, timeout) if err != nil { errs = append(errs, err) } diff --git a/pkg/test/utils/kubernetes_integration_test.go b/pkg/test/utils/kubernetes_integration_test.go index 9763bc77..cdf3a10f 100644 --- a/pkg/test/utils/kubernetes_integration_test.go +++ b/pkg/test/utils/kubernetes_integration_test.go @@ -119,8 +119,9 @@ func TestRunCommand(t *testing.T) { Command: "echo 'hello'", } + logger := NewTestLogger(t, "") // assert foreground cmd returns nil - cmd, err := RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err := RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.NoError(t, err) assert.Nil(t, cmd) // foreground processes should have stdout @@ -130,7 +131,7 @@ func TestRunCommand(t *testing.T) { stdout = &bytes.Buffer{} // assert background cmd returns process - cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.NoError(t, err) assert.NotNil(t, cmd) // no stdout for background processes @@ -141,7 +142,7 @@ func TestRunCommand(t *testing.T) { hcmd.Command = "sleep 42" // assert foreground cmd times out - cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 2) + cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 2) assert.Error(t, err) assert.True(t, strings.Contains(err.Error(), "timeout")) assert.Nil(t, cmd) @@ -152,7 +153,7 @@ func TestRunCommand(t *testing.T) { hcmd.Timeout = 2 // assert foreground cmd times out with command timeout - cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.Error(t, err) assert.True(t, strings.Contains(err.Error(), "timeout")) assert.Nil(t, cmd) @@ -167,13 +168,14 @@ func TestRunCommandIgnoreErrors(t *testing.T) { IgnoreFailure: true, } + logger := NewTestLogger(t, "") // assert foreground cmd returns nil - cmd, err := RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err := RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.NoError(t, err) assert.Nil(t, cmd) hcmd.IgnoreFailure = false - cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.Error(t, err) assert.Nil(t, cmd) @@ -182,7 +184,7 @@ func TestRunCommandIgnoreErrors(t *testing.T) { Command: "bad-command", IgnoreFailure: true, } - cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, 0) + cmd, err = RunCommand(context.TODO(), "", hcmd, "", stdout, stderr, logger, 0) assert.Error(t, err) assert.Nil(t, cmd) }