Skip to content

Commit

Permalink
clean up test directories
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Apr 4, 2022
1 parent 0a250b1 commit 215c80a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions command/operator_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,18 @@ 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
require.NotContains(t, ui.ErrorWriter.String(), "file path escapes capture directory")
require.Contains(t, ui.OutputWriter.String(), "Starting debugger")

path := cmd.collectDir
defer os.Remove(path)

var pluginFiles []string
for _, pluginName := range cases {
Expand Down Expand Up @@ -475,14 +476,16 @@ func TestDebug_CapturedFiles(t *testing.T) {

ui := cli.NewMockUi()
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}
testDir := os.TempDir()
defer os.Remove(testDir)

duration := 2 * time.Second
interval := 750 * time.Millisecond
waitTime := 2 * duration

code := cmd.Run([]string{
"-address", url,
"-output", os.TempDir(),
"-output", testDir,
"-server-id", serverName,
"-node-id", clientID,
"-duration", duration.String(),
Expand All @@ -491,10 +494,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)
Expand Down Expand Up @@ -539,7 +538,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)
}

Expand Down Expand Up @@ -643,11 +644,10 @@ func TestDebug_WriteBytes_Nil(t *testing.T) {
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

testDir = os.TempDir()
cmd.collectDir = testDir
defer os.Remove(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)
Expand Down Expand Up @@ -721,7 +721,6 @@ func TestDebug_CollectConsul(t *testing.T) {
// Setup capture directory
testDir := os.TempDir()
defer os.Remove(testDir)
c.collectDir = testDir

// Collect data from Consul into folder "test"
c.collectConsul("test")
Expand Down Expand Up @@ -764,7 +763,6 @@ func TestDebug_CollectVault(t *testing.T) {
// Set capture directory
testDir := os.TempDir()
defer os.Remove(testDir)
c.collectDir = testDir

// Collect data from Vault
err := c.collectVault("test", "")
Expand Down

0 comments on commit 215c80a

Please sign in to comment.