diff --git a/command/operator_debug_test.go b/command/operator_debug_test.go index 439026c70128..7838b3528650 100644 --- a/command/operator_debug_test.go +++ b/command/operator_debug_test.go @@ -384,9 +384,11 @@ func TestDebug_Bad_CSIPlugin_Names(t *testing.T) { // Setup mock UI ui := cli.NewMockUi() cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}} + testDir := os.TempDir() + defer os.Remove(testDir) // Debug on the leader and all client nodes - code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "leader", "-node-id", "all", "-output", os.TempDir()}) + code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "leader", "-node-id", "all", "-output", testDir}) assert.Equal(t, 0, code) // Bad plugin name should be escaped before it reaches the sandbox test @@ -394,7 +396,6 @@ func TestDebug_Bad_CSIPlugin_Names(t *testing.T) { require.Contains(t, ui.OutputWriter.String(), "Starting debugger") path := cmd.collectDir - defer os.Remove(path) var pluginFiles []string for _, pluginName := range cases { @@ -475,6 +476,10 @@ func TestDebug_CapturedFiles(t *testing.T) { ui := cli.NewMockUi() cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}} + testDir := os.TempDir() + defer os.Remove(testDir) + + cmd.collectDir = testDir duration := 2 * time.Second interval := 750 * time.Millisecond @@ -482,7 +487,7 @@ func TestDebug_CapturedFiles(t *testing.T) { code := cmd.Run([]string{ "-address", url, - "-output", os.TempDir(), + "-output", testDir, "-server-id", serverName, "-node-id", clientID, "-duration", duration.String(), @@ -491,10 +496,6 @@ func TestDebug_CapturedFiles(t *testing.T) { "-pprof-interval", "250ms", }) - // Get capture directory - path := cmd.collectDir - defer os.Remove(path) - // There should be no errors require.Empty(t, ui.ErrorWriter.String()) require.Equal(t, 0, code) @@ -539,7 +540,9 @@ func TestDebug_ExistingOutput(t *testing.T) { os.MkdirAll(path, 0755) defer os.Remove(path) - code := cmd.Run([]string{"-output", os.TempDir(), "-duration", "50ms", "-interval", "50ms"}) + otherTestDir := os.TempDir() + defer os.Remove(otherTestDir) + code := cmd.Run([]string{"-output", otherTestDir, "-duration", "50ms", "-interval", "50ms"}) require.Equal(t, 2, code) } @@ -643,11 +646,12 @@ func TestDebug_WriteBytes_Nil(t *testing.T) { cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}} testDir = os.TempDir() + defer os.Remove(testDir) + cmd.collectDir = testDir testFile = "test_nil.json" testPath = filepath.Join(testDir, testFile) - defer os.Remove(testPath) // Write nil file at top level of collect directory err := cmd.writeBytes("", testFile, testBytes)