diff --git a/agent/acl_test.go b/agent/acl_test.go index e22649db69..303c893374 100644 --- a/agent/acl_test.go +++ b/agent/acl_test.go @@ -3,7 +3,6 @@ package agent import ( "fmt" "io" - "os" "testing" "time" @@ -39,10 +38,6 @@ func NewTestACLAgent(t *testing.T, name string, hcl string, resolveAuthz authzRe a := &TestACLAgent{resolveAuthzFn: resolveAuthz, resolveIdentFn: resolveIdent} dataDir := testutil.TempDir(t, "acl-agent") - t.Cleanup(func() { - os.RemoveAll(dataDir) - }) - logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{ Name: name, Level: hclog.Debug, diff --git a/agent/agent_test.go b/agent/agent_test.go index 4746fd3ff9..94bb74f7ba 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -3511,7 +3511,6 @@ func TestAgent_SecurityChecks(t *testing.T) { func TestAgent_ReloadConfigOutgoingRPCConfig(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "agent") // we manage the data dir - defer os.RemoveAll(dataDir) hcl := ` data_dir = "` + dataDir + `" verify_outgoing = true @@ -3546,7 +3545,6 @@ func TestAgent_ReloadConfigOutgoingRPCConfig(t *testing.T) { func TestAgent_ReloadConfigAndKeepChecksStatus(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "agent") // we manage the data dir - defer os.RemoveAll(dataDir) hcl := `data_dir = "` + dataDir + `" enable_local_script_checks=true services=[{ @@ -3576,7 +3574,6 @@ func TestAgent_ReloadConfigAndKeepChecksStatus(t *testing.T) { func TestAgent_ReloadConfigIncomingRPCConfig(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "agent") // we manage the data dir - defer os.RemoveAll(dataDir) hcl := ` data_dir = "` + dataDir + `" verify_outgoing = true @@ -3616,7 +3613,6 @@ func TestAgent_ReloadConfigIncomingRPCConfig(t *testing.T) { func TestAgent_ReloadConfigTLSConfigFailure(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "agent") // we manage the data dir - defer os.RemoveAll(dataDir) hcl := ` data_dir = "` + dataDir + `" verify_outgoing = true @@ -3645,7 +3641,6 @@ func TestAgent_ReloadConfigTLSConfigFailure(t *testing.T) { func TestAgent_consulConfig_AutoEncryptAllowTLS(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "agent") // we manage the data dir - defer os.RemoveAll(dataDir) hcl := ` data_dir = "` + dataDir + `" verify_incoming = true diff --git a/agent/auto-config/auto_config_test.go b/agent/auto-config/auto_config_test.go index 31a6de785b..a421a45b75 100644 --- a/agent/auto-config/auto_config_test.go +++ b/agent/auto-config/auto_config_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "net" - "os" "path/filepath" "strings" "testing" @@ -162,8 +161,6 @@ func setupRuntimeConfig(t *testing.T) *config.RuntimeConfig { t.Helper() dataDir := testutil.TempDir(t, "auto-config") - t.Cleanup(func() { os.RemoveAll(dataDir) }) - rtConfig := &config.RuntimeConfig{ DataDir: dataDir, Datacenter: "dc1", diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 62ee09e9a5..62118494f1 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -50,7 +50,6 @@ type configTest struct { func TestConfigFlagsAndEdgecases(t *testing.T) { dataDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dataDir) tests := []configTest{ // ------------------------------------------------------------ @@ -4387,7 +4386,6 @@ func testConfig(t *testing.T, tests []configTest, dataDir string) { // func TestFullConfig(t *testing.T) { dataDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dataDir) cidr := func(s string) *net.IPNet { _, n, _ := net.ParseCIDR(s) diff --git a/agent/config/segment_oss_test.go b/agent/config/segment_oss_test.go index 88952e23bc..f432405d05 100644 --- a/agent/config/segment_oss_test.go +++ b/agent/config/segment_oss_test.go @@ -3,7 +3,6 @@ package config import ( - "os" "testing" "github.com/hashicorp/consul/sdk/testutil" @@ -11,7 +10,6 @@ import ( func TestSegments(t *testing.T) { dataDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dataDir) tests := []configTest{ { diff --git a/agent/consul/auto_config_endpoint_test.go b/agent/consul/auto_config_endpoint_test.go index 49c386b210..137b9adcee 100644 --- a/agent/consul/auto_config_endpoint_test.go +++ b/agent/consul/auto_config_endpoint_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "math/rand" "net" - "os" "path" "testing" "time" @@ -394,8 +393,6 @@ func TestAutoConfig_updateTLSSettingsInConfig(t *testing.T) { require.NoError(t, err) dir := testutil.TempDir(t, "auto-config-tls-settings") - t.Cleanup(func() { os.RemoveAll(dir) }) - cafile := path.Join(dir, "cacert.pem") err = ioutil.WriteFile(cafile, []byte(cacert), 0600) require.NoError(t, err) @@ -602,8 +599,6 @@ func TestAutoConfig_updateTLSCertificatesInConfig(t *testing.T) { // this is necessary but creation of the tlsutil.Configurator // will error if it cannot load the CA certificate from disk dir := testutil.TempDir(t, "auto-config-tls-certificate") - t.Cleanup(func() { os.RemoveAll(dir) }) - cafile := path.Join(dir, "cacert.pem") err = ioutil.WriteFile(cafile, []byte(cacert), 0600) require.NoError(t, err) diff --git a/agent/consul/client_test.go b/agent/consul/client_test.go index 569c802a0b..05cafd833a 100644 --- a/agent/consul/client_test.go +++ b/agent/consul/client_test.go @@ -23,9 +23,6 @@ import ( func testClientConfig(t *testing.T) (string, *Config) { dir := testutil.TempDir(t, "consul") - t.Cleanup(func() { - os.RemoveAll(dir) - }) config := DefaultConfig() ports := freeport.MustTake(2) diff --git a/agent/consul/server_test.go b/agent/consul/server_test.go index 6006d3e2c7..95069c9f70 100644 --- a/agent/consul/server_test.go +++ b/agent/consul/server_test.go @@ -129,9 +129,6 @@ func waitForLeaderEstablishment(t *testing.T, servers ...*Server) { func testServerConfig(t *testing.T) (string, *Config) { dir := testutil.TempDir(t, "consul") - t.Cleanup(func() { - os.RemoveAll(dir) - }) config := DefaultConfig() ports := freeport.MustTake(3) diff --git a/agent/http_test.go b/agent/http_test.go index 9136c1eddd..3b68968bf1 100644 --- a/agent/http_test.go +++ b/agent/http_test.go @@ -39,7 +39,6 @@ func TestHTTPServer_UnixSocket(t *testing.T) { } tempDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(tempDir) socket := filepath.Join(tempDir, "test.sock") // Only testing mode, since uid/gid might not be settable @@ -98,7 +97,6 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) { } tempDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(tempDir) socket := filepath.Join(tempDir, "test.sock") // Create a regular file at the socket path diff --git a/agent/keyring_test.go b/agent/keyring_test.go index 16acc01611..15635cb36a 100644 --- a/agent/keyring_test.go +++ b/agent/keyring_test.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "fmt" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -208,7 +207,6 @@ func TestAgent_InmemKeyrings(t *testing.T) { // Any keyring files should be ignored t.Run("ignore files", func(t *testing.T) { dir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dir) badKey := "unUzC2X3JgMKVJlZna5KVg==" if err := initKeyring(filepath.Join(dir, SerfLANKeyring), badKey); err != nil { @@ -254,8 +252,6 @@ func TestAgent_InitKeyring(t *testing.T) { expected := fmt.Sprintf(`["%s"]`, key1) dir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dir) - file := filepath.Join(dir, "keyring") // First initialize the keyring diff --git a/agent/nodeid_test.go b/agent/nodeid_test.go index 6ed2ccfae9..647aea14c5 100644 --- a/agent/nodeid_test.go +++ b/agent/nodeid_test.go @@ -3,7 +3,6 @@ package agent import ( "fmt" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -19,9 +18,6 @@ import ( func TestNewNodeIDFromConfig(t *testing.T) { logger := hclog.New(nil) tmpDir := testutil.TempDir(t, "") - t.Cleanup(func() { - os.RemoveAll(tmpDir) - }) cfg := &config.RuntimeConfig{ DataDir: tmpDir, } diff --git a/agent/routine-leak-checker/leak_test.go b/agent/routine-leak-checker/leak_test.go index 08d69d2a38..fc3ea42f19 100644 --- a/agent/routine-leak-checker/leak_test.go +++ b/agent/routine-leak-checker/leak_test.go @@ -6,7 +6,6 @@ import ( "crypto/rand" "crypto/x509" "io/ioutil" - "os" "path/filepath" "testing" @@ -58,7 +57,6 @@ func testTLSCertificates(serverName string) (cert string, key string, cacert str func setupPrimaryServer(t *testing.T) *agent.TestAgent { d := testutil.TempDir(t, "leaks-primary-server") - t.Cleanup(func() { os.RemoveAll(d) }) certPEM, keyPEM, caPEM, err := testTLSCertificates("server.primary.consul") require.NoError(t, err) diff --git a/agent/ui_endpoint_test.go b/agent/ui_endpoint_test.go index eab3c4193c..80ed8e0b33 100644 --- a/agent/ui_endpoint_test.go +++ b/agent/ui_endpoint_test.go @@ -8,7 +8,6 @@ import ( "net/http" "net/http/httptest" "net/url" - "os" "path/filepath" "testing" @@ -25,7 +24,6 @@ func TestUiIndex(t *testing.T) { t.Parallel() // Make a test dir to serve UI files uiDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(uiDir) // Make the server a := NewTestAgent(t, ` diff --git a/api/agent_test.go b/api/agent_test.go index 57b5247322..dd96491ccc 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -85,7 +85,6 @@ func TestAPI_AgentReload(t *testing.T) { // Create our initial empty config file, to be overwritten later cfgDir := testutil.TempDir(t, "consul-config") - defer os.RemoveAll(cfgDir) cfgFilePath := filepath.Join(cfgDir, "reload.json") configFile, err := os.Create(cfgFilePath) diff --git a/api/api_test.go b/api/api_test.go index 39ae0e4c2c..b52ab97a2b 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -867,7 +867,6 @@ func TestAPI_UnixSocket(t *testing.T) { } tempDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(tempDir) socket := filepath.Join(tempDir, "test.sock") c, s := makeClientWithConfig(t, func(c *Config) { diff --git a/command/acl/agenttokens/agent_tokens_test.go b/command/acl/agenttokens/agent_tokens_test.go index 832f45ed0b..b006199d63 100644 --- a/command/acl/agenttokens/agent_tokens_test.go +++ b/command/acl/agenttokens/agent_tokens_test.go @@ -1,13 +1,11 @@ package agenttokens import ( - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -25,9 +23,6 @@ func TestAgentTokensCommand(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/authmethod/create/authmethod_create_test.go b/command/acl/authmethod/create/authmethod_create_test.go index 389275e60f..a0c4c954ff 100644 --- a/command/acl/authmethod/create/authmethod_create_test.go +++ b/command/acl/authmethod/create/authmethod_create_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "io" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -35,9 +34,6 @@ func TestAuthMethodCreateCommand_noTabs(t *testing.T) { func TestAuthMethodCreateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -188,9 +184,6 @@ func TestAuthMethodCreateCommand(t *testing.T) { func TestAuthMethodCreateCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -357,7 +350,6 @@ func TestAuthMethodCreateCommand_k8s(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -500,7 +492,6 @@ func TestAuthMethodCreateCommand_config(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "auth-method") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/acl/authmethod/delete/authmethod_delete_test.go b/command/acl/authmethod/delete/authmethod_delete_test.go index e77d7892d8..1b4680494d 100644 --- a/command/acl/authmethod/delete/authmethod_delete_test.go +++ b/command/acl/authmethod/delete/authmethod_delete_test.go @@ -2,13 +2,11 @@ package authmethoddelete import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -29,9 +27,6 @@ func TestAuthMethodDeleteCommand_noTabs(t *testing.T) { func TestAuthMethodDeleteCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/authmethod/list/authmethod_list_test.go b/command/acl/authmethod/list/authmethod_list_test.go index 18b7e45ca5..9c5050a2e9 100644 --- a/command/acl/authmethod/list/authmethod_list_test.go +++ b/command/acl/authmethod/list/authmethod_list_test.go @@ -2,13 +2,11 @@ package authmethodlist import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -30,9 +28,6 @@ func TestAuthMethodListCommand_noTabs(t *testing.T) { func TestAuthMethodListCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -110,9 +105,6 @@ func TestAuthMethodListCommand(t *testing.T) { func TestAuthMethodListCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/authmethod/read/authmethod_read_test.go b/command/acl/authmethod/read/authmethod_read_test.go index e0cf2c5c12..021de5cfcb 100644 --- a/command/acl/authmethod/read/authmethod_read_test.go +++ b/command/acl/authmethod/read/authmethod_read_test.go @@ -2,13 +2,11 @@ package authmethodread import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -30,9 +28,6 @@ func TestAuthMethodReadCommand_noTabs(t *testing.T) { func TestAuthMethodReadCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -119,9 +114,6 @@ func TestAuthMethodReadCommand(t *testing.T) { func TestAuthMethodReadCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/authmethod/update/authmethod_update_test.go b/command/acl/authmethod/update/authmethod_update_test.go index 0beb95ce3a..0020fa7dbc 100644 --- a/command/acl/authmethod/update/authmethod_update_test.go +++ b/command/acl/authmethod/update/authmethod_update_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "io" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -34,9 +33,6 @@ func TestAuthMethodUpdateCommand_noTabs(t *testing.T) { func TestAuthMethodUpdateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -170,9 +166,6 @@ func TestAuthMethodUpdateCommand(t *testing.T) { func TestAuthMethodUpdateCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -260,9 +253,6 @@ func TestAuthMethodUpdateCommand_JSON(t *testing.T) { func TestAuthMethodUpdateCommand_noMerge(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -362,7 +352,6 @@ func TestAuthMethodUpdateCommand_k8s(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -597,7 +586,6 @@ func TestAuthMethodUpdateCommand_k8s_noMerge(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -784,7 +772,6 @@ func TestAuthMethodUpdateCommand_k8s_noMerge(t *testing.T) { func TestAuthMethodUpdateCommand_config(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "auth-method") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/acl/bindingrule/create/bindingrule_create_test.go b/command/acl/bindingrule/create/bindingrule_create_test.go index 8c41d413af..acd843fb95 100644 --- a/command/acl/bindingrule/create/bindingrule_create_test.go +++ b/command/acl/bindingrule/create/bindingrule_create_test.go @@ -2,13 +2,11 @@ package bindingrulecreate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -29,9 +27,6 @@ func TestBindingRuleCreateCommand_noTabs(t *testing.T) { func TestBindingRuleCreateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -179,9 +174,6 @@ func TestBindingRuleCreateCommand(t *testing.T) { func TestBindingRuleCreateCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/bindingrule/delete/bindingrule_delete_test.go b/command/acl/bindingrule/delete/bindingrule_delete_test.go index be1f41db94..c972566de1 100644 --- a/command/acl/bindingrule/delete/bindingrule_delete_test.go +++ b/command/acl/bindingrule/delete/bindingrule_delete_test.go @@ -2,13 +2,11 @@ package bindingruledelete import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/require" @@ -28,9 +26,6 @@ func TestBindingRuleDeleteCommand_noTabs(t *testing.T) { func TestBindingRuleDeleteCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/bindingrule/list/bindingrule_list_test.go b/command/acl/bindingrule/list/bindingrule_list_test.go index eb2752b6c4..677b5ac308 100644 --- a/command/acl/bindingrule/list/bindingrule_list_test.go +++ b/command/acl/bindingrule/list/bindingrule_list_test.go @@ -3,13 +3,11 @@ package bindingrulelist import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -30,9 +28,6 @@ func TestBindingRuleListCommand_noTabs(t *testing.T) { func TestBindingRuleListCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/bindingrule/read/bindingrule_read_test.go b/command/acl/bindingrule/read/bindingrule_read_test.go index 5d8e31edb5..5f630889bb 100644 --- a/command/acl/bindingrule/read/bindingrule_read_test.go +++ b/command/acl/bindingrule/read/bindingrule_read_test.go @@ -2,13 +2,11 @@ package bindingruleread import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -29,9 +27,6 @@ func TestBindingRuleReadCommand_noTabs(t *testing.T) { func TestBindingRuleReadCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/bindingrule/update/bindingrule_update_test.go b/command/acl/bindingrule/update/bindingrule_update_test.go index ae985cf7ae..a41ab82dc9 100644 --- a/command/acl/bindingrule/update/bindingrule_update_test.go +++ b/command/acl/bindingrule/update/bindingrule_update_test.go @@ -2,13 +2,11 @@ package bindingruleupdate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" uuid "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -30,9 +28,6 @@ func TestBindingRuleUpdateCommand_noTabs(t *testing.T) { func TestBindingRuleUpdateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -470,9 +465,6 @@ func TestBindingRuleUpdateCommand(t *testing.T) { func TestBindingRuleUpdateCommand_noMerge(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/bootstrap/bootstrap_test.go b/command/acl/bootstrap/bootstrap_test.go index 6dffd98343..d4ed1fa045 100644 --- a/command/acl/bootstrap/bootstrap_test.go +++ b/command/acl/bootstrap/bootstrap_test.go @@ -2,13 +2,11 @@ package bootstrap import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/agent/structs" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -27,9 +25,6 @@ func TestBootstrapCommand_Pretty(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -58,9 +53,6 @@ func TestBootstrapCommand_JSON(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/policy/create/policy_create_test.go b/command/acl/policy/create/policy_create_test.go index c90e29e107..a1d2027e01 100644 --- a/command/acl/policy/create/policy_create_test.go +++ b/command/acl/policy/create/policy_create_test.go @@ -3,7 +3,6 @@ package policycreate import ( "encoding/json" "io/ioutil" - "os" "strings" "testing" @@ -28,7 +27,6 @@ func TestPolicyCreateCommand(t *testing.T) { require := require.New(t) testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -66,7 +64,6 @@ func TestPolicyCreateCommand_JSON(t *testing.T) { require := require.New(t) testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/acl/policy/delete/policy_delete_test.go b/command/acl/policy/delete/policy_delete_test.go index 485c086123..03df12dfe6 100644 --- a/command/acl/policy/delete/policy_delete_test.go +++ b/command/acl/policy/delete/policy_delete_test.go @@ -2,13 +2,11 @@ package policydelete import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -26,9 +24,6 @@ func TestPolicyDeleteCommand(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/policy/list/policy_list_test.go b/command/acl/policy/list/policy_list_test.go index 2ce7892043..01fc40b2c0 100644 --- a/command/acl/policy/list/policy_list_test.go +++ b/command/acl/policy/list/policy_list_test.go @@ -3,13 +3,11 @@ package policylist import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -27,9 +25,6 @@ func TestPolicyListCommand(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -81,9 +76,6 @@ func TestPolicyListCommand_JSON(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/policy/read/policy_read_test.go b/command/acl/policy/read/policy_read_test.go index 8477e6c25f..86825b5cf1 100644 --- a/command/acl/policy/read/policy_read_test.go +++ b/command/acl/policy/read/policy_read_test.go @@ -3,13 +3,11 @@ package policyread import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -27,9 +25,6 @@ func TestPolicyReadCommand(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -73,9 +68,6 @@ func TestPolicyReadCommand_JSON(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/policy/update/policy_update_test.go b/command/acl/policy/update/policy_update_test.go index 16c6bcb70d..e3c3359245 100644 --- a/command/acl/policy/update/policy_update_test.go +++ b/command/acl/policy/update/policy_update_test.go @@ -3,7 +3,6 @@ package policyupdate import ( "encoding/json" "io/ioutil" - "os" "strings" "testing" @@ -28,7 +27,6 @@ func TestPolicyUpdateCommand(t *testing.T) { assert := assert.New(t) testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -76,7 +74,6 @@ func TestPolicyUpdateCommand_JSON(t *testing.T) { assert := assert.New(t) testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/acl/role/create/role_create_test.go b/command/acl/role/create/role_create_test.go index b3c03a662a..ce4e94bcc4 100644 --- a/command/acl/role/create/role_create_test.go +++ b/command/acl/role/create/role_create_test.go @@ -2,13 +2,11 @@ package rolecreate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -26,9 +24,6 @@ func TestRoleCreateCommand_noTabs(t *testing.T) { func TestRoleCreateCommand_Pretty(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -118,9 +113,6 @@ func TestRoleCreateCommand_Pretty(t *testing.T) { func TestRoleCreateCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/role/delete/role_delete_test.go b/command/acl/role/delete/role_delete_test.go index e2abeeac75..34b9cdd5fb 100644 --- a/command/acl/role/delete/role_delete_test.go +++ b/command/acl/role/delete/role_delete_test.go @@ -2,13 +2,11 @@ package roledelete import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/require" @@ -25,9 +23,6 @@ func TestRoleDeleteCommand_noTabs(t *testing.T) { func TestRoleDeleteCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/role/list/role_list_test.go b/command/acl/role/list/role_list_test.go index 203630c699..b656952ac1 100644 --- a/command/acl/role/list/role_list_test.go +++ b/command/acl/role/list/role_list_test.go @@ -3,13 +3,11 @@ package rolelist import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -28,9 +26,6 @@ func TestRoleListCommand(t *testing.T) { t.Parallel() require := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -85,9 +80,6 @@ func TestRoleListCommand_JSON(t *testing.T) { t.Parallel() require := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/role/read/role_read_test.go b/command/acl/role/read/role_read_test.go index 588fe6a493..497cd37247 100644 --- a/command/acl/role/read/role_read_test.go +++ b/command/acl/role/read/role_read_test.go @@ -3,13 +3,11 @@ package roleread import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -28,9 +26,6 @@ func TestRoleReadCommand_noTabs(t *testing.T) { func TestRoleReadCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -195,9 +190,6 @@ func TestRoleReadCommand(t *testing.T) { func TestRoleReadCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/role/update/role_update_test.go b/command/acl/role/update/role_update_test.go index c7c59bd973..9cec59b38d 100644 --- a/command/acl/role/update/role_update_test.go +++ b/command/acl/role/update/role_update_test.go @@ -2,13 +2,11 @@ package roleupdate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -28,9 +26,6 @@ func TestRoleUpdateCommand_noTabs(t *testing.T) { func TestRoleUpdateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -201,9 +196,6 @@ func TestRoleUpdateCommand(t *testing.T) { func TestRoleUpdateCommand_JSON(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -283,9 +275,6 @@ func TestRoleUpdateCommand_JSON(t *testing.T) { func TestRoleUpdateCommand_noMerge(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/rules/translate_test.go b/command/acl/rules/translate_test.go index a06110a40f..47f19d0053 100644 --- a/command/acl/rules/translate_test.go +++ b/command/acl/rules/translate_test.go @@ -3,7 +3,6 @@ package rules import ( "io" "io/ioutil" - "os" "strings" "testing" @@ -26,7 +25,6 @@ func TestRulesTranslateCommand(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/acl/token/clone/token_clone_test.go b/command/acl/token/clone/token_clone_test.go index 76daf405d3..d1028a9c18 100644 --- a/command/acl/token/clone/token_clone_test.go +++ b/command/acl/token/clone/token_clone_test.go @@ -2,7 +2,6 @@ package tokenclone import ( "encoding/json" - "os" "regexp" "strconv" "strings" @@ -10,7 +9,6 @@ import ( "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -63,9 +61,6 @@ func TestTokenCloneCommand_Pretty(t *testing.T) { t.Parallel() req := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -170,9 +165,6 @@ func TestTokenCloneCommand_JSON(t *testing.T) { t.Parallel() req := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/token/create/token_create_test.go b/command/acl/token/create/token_create_test.go index a128c2f14b..c364b82d1e 100644 --- a/command/acl/token/create/token_create_test.go +++ b/command/acl/token/create/token_create_test.go @@ -2,13 +2,11 @@ package tokencreate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/require" @@ -25,9 +23,6 @@ func TestTokenCreateCommand_noTabs(t *testing.T) { func TestTokenCreateCommand_Pretty(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" node_name = "test-node" @@ -123,9 +118,6 @@ func TestTokenCreateCommand_JSON(t *testing.T) { t.Parallel() require := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/token/delete/token_delete_test.go b/command/acl/token/delete/token_delete_test.go index 30b27b8c26..9af72026d1 100644 --- a/command/acl/token/delete/token_delete_test.go +++ b/command/acl/token/delete/token_delete_test.go @@ -2,13 +2,11 @@ package tokendelete import ( "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -26,9 +24,6 @@ func TestTokenDeleteCommand(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/token/list/token_list_test.go b/command/acl/token/list/token_list_test.go index fe3d9da43f..a9f41a4da9 100644 --- a/command/acl/token/list/token_list_test.go +++ b/command/acl/token/list/token_list_test.go @@ -3,13 +3,11 @@ package tokenlist import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -28,9 +26,6 @@ func TestTokenListCommand_Pretty(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -82,9 +77,6 @@ func TestTokenListCommand_JSON(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/token/read/token_read_test.go b/command/acl/token/read/token_read_test.go index d046848e1a..a70cca5d3f 100644 --- a/command/acl/token/read/token_read_test.go +++ b/command/acl/token/read/token_read_test.go @@ -3,13 +3,11 @@ package tokenread import ( "encoding/json" "fmt" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" "github.com/stretchr/testify/assert" @@ -28,9 +26,6 @@ func TestTokenReadCommand_Pretty(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -75,9 +70,6 @@ func TestTokenReadCommand_JSON(t *testing.T) { t.Parallel() assert := assert.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/acl/token/update/token_update_test.go b/command/acl/token/update/token_update_test.go index cf8cc2d767..d273058caa 100644 --- a/command/acl/token/update/token_update_test.go +++ b/command/acl/token/update/token_update_test.go @@ -2,13 +2,11 @@ package tokenupdate import ( "encoding/json" - "os" "strings" "testing" "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil/retry" "github.com/hashicorp/consul/testrpc" "github.com/mitchellh/cli" @@ -27,9 +25,6 @@ func TestTokenUpdateCommand_noTabs(t *testing.T) { func TestTokenUpdateCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -199,9 +194,6 @@ func TestTokenUpdateCommand_JSON(t *testing.T) { // Alias because we need to access require package in Retry below req := require.New(t) - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 049ddcc19d..b2b50145d3 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -21,7 +21,6 @@ func TestConfigFail(t *testing.T) { t.Parallel() dataDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dataDir) tests := []struct { args []string @@ -108,7 +107,6 @@ func TestRetryJoin(t *testing.T) { func TestRetryJoinFail(t *testing.T) { t.Parallel() tmpDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(tmpDir) ui := cli.NewMockUi() cmd := New(ui, "", "", "", "", nil) @@ -129,7 +127,6 @@ func TestRetryJoinFail(t *testing.T) { func TestRetryJoinWanFail(t *testing.T) { t.Parallel() tmpDir := testutil.TempDir(t, "consul") - defer os.RemoveAll(tmpDir) ui := cli.NewMockUi() cmd := New(ui, "", "", "", "", nil) @@ -151,14 +148,12 @@ func TestRetryJoinWanFail(t *testing.T) { func TestProtectDataDir(t *testing.T) { t.Parallel() dir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dir) if err := os.MkdirAll(filepath.Join(dir, "mdb"), 0700); err != nil { t.Fatalf("err: %v", err) } cfgDir := testutil.TempDir(t, "consul-config") - defer os.RemoveAll(cfgDir) cfgFilePath := filepath.Join(cfgDir, "consul.json") cfgFile, err := os.Create(cfgFilePath) @@ -186,13 +181,10 @@ func TestProtectDataDir(t *testing.T) { func TestBadDataDirPermissions(t *testing.T) { t.Parallel() dir := testutil.TempDir(t, "consul") - defer os.RemoveAll(dir) - dataDir := filepath.Join(dir, "mdb") if err := os.MkdirAll(dataDir, 0400); err != nil { t.Fatalf("err: %v", err) } - defer os.RemoveAll(dataDir) ui := cli.NewMockUi() cmd := New(ui, "", "", "", "", nil) diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index df089d12de..d99051b1e3 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -3,7 +3,6 @@ package envoy import ( "encoding/json" "flag" - "github.com/stretchr/testify/assert" "io/ioutil" "net" "net/http" @@ -13,6 +12,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" + "github.com/hashicorp/consul/agent" "github.com/hashicorp/consul/agent/xds" "github.com/hashicorp/consul/api" @@ -685,7 +686,6 @@ func TestGenerateConfig(t *testing.T) { require := require.New(t) testDir := testutil.TempDir(t, "envoytest") - defer os.RemoveAll(testDir) if len(tc.Files) > 0 { for fn, fv := range tc.Files { diff --git a/command/debug/debug_test.go b/command/debug/debug_test.go index 462b6c17ec..2afb3bf652 100644 --- a/command/debug/debug_test.go +++ b/command/debug/debug_test.go @@ -28,7 +28,6 @@ func TestDebugCommand(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` enable_debug = true @@ -65,7 +64,6 @@ func TestDebugCommand_Archive(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` enable_debug = true @@ -125,9 +123,6 @@ func TestDebugCommand_Archive(t *testing.T) { func TestDebugCommand_ArgsBad(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) - ui := cli.NewMockUi() cmd := New(ui, nil) @@ -149,9 +144,6 @@ func TestDebugCommand_ArgsBad(t *testing.T) { func TestDebugCommand_OutputPathBad(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, "") defer a.Shutdown() testrpc.WaitForLeader(t, a.RPC, "dc1") @@ -182,7 +174,6 @@ func TestDebugCommand_OutputPathExists(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, "") defer a.Shutdown() @@ -263,7 +254,6 @@ func TestDebugCommand_CaptureTargets(t *testing.T) { for name, tc := range cases { testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` enable_debug = true @@ -329,7 +319,6 @@ func TestDebugCommand_ProfilesExist(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` enable_debug = true @@ -406,9 +395,6 @@ func TestDebugCommand_ValidateTiming(t *testing.T) { // the valid duration test to avoid hanging shutdownCh := make(chan struct{}) - testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, "") defer a.Shutdown() testrpc.WaitForLeader(t, a.RPC, "dc1") @@ -439,7 +425,6 @@ func TestDebugCommand_DebugDisabled(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "debug") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` enable_debug = false diff --git a/command/login/login_test.go b/command/login/login_test.go index c34766f276..e821eddb02 100644 --- a/command/login/login_test.go +++ b/command/login/login_test.go @@ -34,7 +34,6 @@ func TestLoginCommand(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -228,7 +227,6 @@ func TestLoginCommand_k8s(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" @@ -323,7 +321,6 @@ func TestLoginCommand_jwt(t *testing.T) { t.Parallel() testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" diff --git a/command/logout/logout_test.go b/command/logout/logout_test.go index 07b2f8df10..e04a5bd817 100644 --- a/command/logout/logout_test.go +++ b/command/logout/logout_test.go @@ -1,7 +1,6 @@ package logout import ( - "os" "strings" "testing" @@ -10,7 +9,6 @@ import ( "github.com/hashicorp/consul/agent/consul/authmethod/testauth" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/command/acl" - "github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/go-uuid" "github.com/mitchellh/cli" @@ -28,9 +26,6 @@ func TestLogout_noTabs(t *testing.T) { func TestLogoutCommand(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { @@ -157,9 +152,6 @@ func TestLogoutCommand(t *testing.T) { func TestLogoutCommand_k8s(t *testing.T) { t.Parallel() - testDir := testutil.TempDir(t, "acl") - defer os.RemoveAll(testDir) - a := agent.NewTestAgent(t, ` primary_datacenter = "dc1" acl { diff --git a/command/snapshot/inspect/snapshot_inspect_test.go b/command/snapshot/inspect/snapshot_inspect_test.go index 56fd25110d..eab43a8f4d 100644 --- a/command/snapshot/inspect/snapshot_inspect_test.go +++ b/command/snapshot/inspect/snapshot_inspect_test.go @@ -66,8 +66,6 @@ func TestSnapshotInspectCommand(t *testing.T) { client := a.Client() dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) - file := filepath.Join(dir, "backup.tgz") // Save a snapshot of the current Consul state diff --git a/command/snapshot/restore/snapshot_restore_test.go b/command/snapshot/restore/snapshot_restore_test.go index 36163a0f3d..a26361229a 100644 --- a/command/snapshot/restore/snapshot_restore_test.go +++ b/command/snapshot/restore/snapshot_restore_test.go @@ -74,8 +74,6 @@ func TestSnapshotRestoreCommand(t *testing.T) { c := New(ui) dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) - file := filepath.Join(dir, "backup.tgz") args := []string{ "-http-addr=" + a.HTTPAddr(), @@ -134,7 +132,6 @@ func TestSnapshotRestoreCommand_TruncatedSnapshot(t *testing.T) { } dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) for _, removeBytes := range []int{200, 16, 8, 4, 2, 1} { t.Run(fmt.Sprintf("truncate %d bytes from end", removeBytes), func(t *testing.T) { diff --git a/command/snapshot/save/snapshot_save_test.go b/command/snapshot/save/snapshot_save_test.go index c7c5331f95..db0c4b48d4 100644 --- a/command/snapshot/save/snapshot_save_test.go +++ b/command/snapshot/save/snapshot_save_test.go @@ -78,8 +78,6 @@ func TestSnapshotSaveCommand(t *testing.T) { c := New(ui) dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) - file := filepath.Join(dir, "backup.tgz") args := []string{ "-http-addr=" + a.HTTPAddr(), @@ -160,7 +158,6 @@ func TestSnapshotSaveCommand_TruncatedStream(t *testing.T) { }) dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) for _, removeBytes := range []int{200, 16, 8, 4, 2, 1} { t.Run(fmt.Sprintf("truncate %d bytes from end", removeBytes), func(t *testing.T) { diff --git a/command/tls/ca/create/tls_ca_create_test.go b/command/tls/ca/create/tls_ca_create_test.go index 88345fdae7..f2677e081d 100644 --- a/command/tls/ca/create/tls_ca_create_test.go +++ b/command/tls/ca/create/tls_ca_create_test.go @@ -24,7 +24,6 @@ func TestValidateCommand_noTabs(t *testing.T) { func TestCACreateCommand(t *testing.T) { testDir := testutil.TempDir(t, "ca-create") - defer os.RemoveAll(testDir) defer switchToTempDir(t, testDir)() diff --git a/command/tls/cert/create/tls_cert_create_test.go b/command/tls/cert/create/tls_cert_create_test.go index 736a159ef1..306eed8df2 100644 --- a/command/tls/cert/create/tls_cert_create_test.go +++ b/command/tls/cert/create/tls_cert_create_test.go @@ -74,7 +74,6 @@ func TestTlsCertCreateCommand_InvalidArgs(t *testing.T) { func TestTlsCertCreateCommand_fileCreate(t *testing.T) { testDir := testutil.TempDir(t, "tls") - defer os.RemoveAll(testDir) defer switchToTempDir(t, testDir)() diff --git a/command/validate/validate_test.go b/command/validate/validate_test.go index cb37cdb370..a00a173589 100644 --- a/command/validate/validate_test.go +++ b/command/validate/validate_test.go @@ -34,7 +34,6 @@ func TestValidateCommand_FailOnEmptyFile(t *testing.T) { func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "config.json") err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644) @@ -50,7 +49,6 @@ func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) { func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "json.conf") err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644) @@ -66,7 +64,6 @@ func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) { func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "hcl.conf") err := ioutil.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644) @@ -82,7 +79,6 @@ func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) { func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "json.conf") err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644) @@ -98,7 +94,6 @@ func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) { func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644) require.Nilf(t, err, "err: %s", err) @@ -113,7 +108,6 @@ func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) { func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "hcl.conf") err := ioutil.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644) @@ -129,7 +123,6 @@ func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) { func TestValidateCommand_Quiet(t *testing.T) { t.Parallel() td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) fp := filepath.Join(td, "config.json") err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644) diff --git a/command/watch/watch_test.go b/command/watch/watch_test.go index 2bd74e08a3..4b6d72e890 100644 --- a/command/watch/watch_test.go +++ b/command/watch/watch_test.go @@ -48,7 +48,6 @@ func TestWatchCommand_loadToken(t *testing.T) { const testToken = "4a0db5a1-869f-4602-ae8a-b0306a82f1ef" testDir := testutil.TempDir(t, "watchtest") - defer os.RemoveAll(testDir) fullname := filepath.Join(testDir, "token.txt") require.NoError(t, ioutil.WriteFile(fullname, []byte(testToken), 0600)) diff --git a/logging/logfile_test.go b/logging/logfile_test.go index e035a9c939..c1343d0556 100644 --- a/logging/logfile_test.go +++ b/logging/logfile_test.go @@ -2,7 +2,6 @@ package logging import ( "io/ioutil" - "os" "path/filepath" "testing" "time" @@ -19,7 +18,6 @@ const ( func TestLogFile_timeRotation(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, "LogWriterTime") - defer os.Remove(tempDir) logFile := LogFile{ fileName: testFileName, logPath: tempDir, @@ -37,7 +35,6 @@ func TestLogFile_timeRotation(t *testing.T) { func TestLogFile_openNew(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, "LogWriterOpen") - defer os.Remove(tempDir) logFile := LogFile{fileName: testFileName, logPath: tempDir, duration: testDuration} if err := logFile.openNew(); err != nil { t.Errorf("Expected open file %s, got an error (%s)", testFileName, err) @@ -51,7 +48,6 @@ func TestLogFile_openNew(t *testing.T) { func TestLogFile_byteRotation(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, "LogWriterBytes") - defer os.Remove(tempDir) logFile := LogFile{ fileName: testFileName, logPath: tempDir, @@ -70,7 +66,6 @@ func TestLogFile_byteRotation(t *testing.T) { func TestLogFile_deleteArchives(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, "LogWriteDeleteArchives") - defer os.Remove(tempDir) logFile := LogFile{ fileName: testFileName, logPath: tempDir, @@ -107,7 +102,6 @@ func TestLogFile_deleteArchives(t *testing.T) { func TestLogFile_deleteArchivesDisabled(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, t.Name()) - defer os.Remove(tempDir) logFile := LogFile{ fileName: testFileName, logPath: tempDir, @@ -129,7 +123,6 @@ func TestLogFile_deleteArchivesDisabled(t *testing.T) { func TestLogFile_rotationDisabled(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, t.Name()) - defer os.Remove(tempDir) logFile := LogFile{ fileName: testFileName, logPath: tempDir, diff --git a/logging/logger_test.go b/logging/logger_test.go index d7eb9b04dd..f6ffc78802 100644 --- a/logging/logger_test.go +++ b/logging/logger_test.go @@ -145,7 +145,6 @@ func TestLogger_SetupLoggerWithValidLogPath(t *testing.T) { require := require.New(t) tmpDir := testutil.TempDir(t, t.Name()) - defer os.RemoveAll(tmpDir) cfg := &Config{ LogLevel: "INFO", diff --git a/snapshot/snapshot_test.go b/snapshot/snapshot_test.go index 86e8662589..a3e91688ec 100644 --- a/snapshot/snapshot_test.go +++ b/snapshot/snapshot_test.go @@ -5,7 +5,6 @@ import ( "crypto/rand" "fmt" "io" - "os" "path/filepath" "strings" "sync" @@ -126,7 +125,6 @@ func makeRaft(t *testing.T, dir string) (*raft.Raft, *MockFSM) { func TestSnapshot(t *testing.T) { dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) // Make a Raft and populate it with some data. We tee everything we // apply off to a buffer for checking post-snapshot. @@ -235,7 +233,6 @@ func TestSnapshot_BadVerify(t *testing.T) { func TestSnapshot_TruncatedVerify(t *testing.T) { dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) // Make a Raft and populate it with some data. We tee everything we // apply off to a buffer for checking post-snapshot. @@ -281,7 +278,6 @@ func TestSnapshot_TruncatedVerify(t *testing.T) { func TestSnapshot_BadRestore(t *testing.T) { dir := testutil.TempDir(t, "snapshot") - defer os.RemoveAll(dir) // Make a Raft and populate it with some data. before, _ := makeRaft(t, filepath.Join(dir, "before"))