From 3522a41bade689519747dba779622d7fe87eae2b Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Fri, 12 May 2017 10:34:50 +0200 Subject: [PATCH] test: include test name in temp file/dir This helps identifying hanging tests by looking at the process list. --- api/agent_test.go | 2 +- api/api_test.go | 4 ++-- command/agent/acl_test.go | 2 +- command/agent/agent_endpoint_test.go | 2 +- command/agent/agent_test.go | 4 ++-- command/agent/command_test.go | 14 +++++++------- command/agent/config_test.go | 4 ++-- command/agent/http_test.go | 8 ++++---- command/agent/keyring_test.go | 2 +- command/agent/ui_endpoint_test.go | 2 +- command/agent/util_test.go | 2 +- command/configtest_test.go | 10 +++++----- command/kv_put_test.go | 2 +- command/snapshot_inspect_test.go | 2 +- command/snapshot_restore_test.go | 2 +- command/snapshot_save_test.go | 2 +- command/util_test.go | 2 +- command/validate_test.go | 12 ++++++------ consul/server_test.go | 2 +- snapshot/snapshot_test.go | 4 ++-- testutil/server.go | 10 +++++----- 21 files changed, 47 insertions(+), 47 deletions(-) diff --git a/api/agent_test.go b/api/agent_test.go index 2096eb477c..89b797e9e9 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -32,7 +32,7 @@ func TestAgent_Reload(t *testing.T) { t.Parallel() // Create our initial empty config file, to be overwritten later - configFile, err := ioutil.TempFile("", "reload") + configFile, err := ioutil.TempFile("", t.Name()+"-reload") if err != nil { t.Fatalf("err: %s", err) } diff --git a/api/api_test.go b/api/api_test.go index 0837739594..79f812590f 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -44,7 +44,7 @@ func makeClientWithConfig( cb1(conf) } // Create server - server, err := testutil.NewTestServerConfig(cb2) + server, err := testutil.NewTestServerConfig(t.Name(), cb2) if err != nil { t.Fatal(err) } @@ -481,7 +481,7 @@ func TestAPI_UnixSocket(t *testing.T) { t.SkipNow() } - tempDir, err := ioutil.TempDir("", "consul") + tempDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/agent/acl_test.go b/command/agent/acl_test.go index 92b67256aa..5399e8ca5f 100644 --- a/command/agent/acl_test.go +++ b/command/agent/acl_test.go @@ -21,7 +21,7 @@ func TestACL_Bad_Config(t *testing.T) { config.ACLDownPolicy = "nope" var err error - config.DataDir, err = ioutil.TempDir("", "agent") + config.DataDir, err = ioutil.TempDir("", t.Name()+"-agent") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index 910b78db48..0f65c18afb 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -243,7 +243,7 @@ func TestAgent_Self_ACLDeny(t *testing.T) { func TestAgent_Reload(t *testing.T) { conf := nextConfig() - tmpDir, err := ioutil.TempDir("", "consul") + tmpDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 81a57684ee..5787707ef2 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -95,7 +95,7 @@ func nextConfig() *Config { } func makeAgentLog(t *testing.T, conf *Config, l io.Writer, writer *logger.LogWriter) (string, *Agent) { - dir, err := ioutil.TempDir("", "agent") + dir, err := ioutil.TempDir("", t.Name()+"-agent") if err != nil { t.Fatalf(fmt.Sprintf("err: %v", err)) } @@ -111,7 +111,7 @@ func makeAgentLog(t *testing.T, conf *Config, l io.Writer, writer *logger.LogWri } func makeAgentKeyring(t *testing.T, conf *Config, key string) (string, *Agent) { - dir, err := ioutil.TempDir("", "agent") + dir, err := ioutil.TempDir("", t.Name()+"-agent") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/command_test.go b/command/agent/command_test.go index 1588fe8614..dcb997e714 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -103,7 +103,7 @@ func TestRetryJoin(t *testing.T) { defer agent.Shutdown() conf2 := nextConfig() - tmpDir, err := ioutil.TempDir("", "consul") + tmpDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -161,7 +161,7 @@ func TestRetryJoin(t *testing.T) { } func TestReadCliConfig(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "consul") + tmpDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -293,7 +293,7 @@ func TestReadCliConfig(t *testing.T) { func TestRetryJoinFail(t *testing.T) { conf := nextConfig() - tmpDir, err := ioutil.TempDir("", "consul") + tmpDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -323,7 +323,7 @@ func TestRetryJoinFail(t *testing.T) { func TestRetryJoinWanFail(t *testing.T) { conf := nextConfig() - tmpDir, err := ioutil.TempDir("", "consul") + tmpDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -410,7 +410,7 @@ func TestDiscoverGCEHosts(t *testing.T) { } func TestProtectDataDir(t *testing.T) { - dir, err := ioutil.TempDir("", "consul") + dir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %v", err) } @@ -420,7 +420,7 @@ func TestProtectDataDir(t *testing.T) { t.Fatalf("err: %v", err) } - cfgFile, err := ioutil.TempFile("", "consul") + cfgFile, err := ioutil.TempFile("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %v", err) } @@ -446,7 +446,7 @@ func TestProtectDataDir(t *testing.T) { } func TestBadDataDirPermissions(t *testing.T) { - dir, err := ioutil.TempDir("", "consul") + dir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index c446ec2566..726494adb8 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -1797,7 +1797,7 @@ func TestReadConfigPaths_badPath(t *testing.T) { } func TestReadConfigPaths_file(t *testing.T) { - tf, err := ioutil.TempFile("", "consul") + tf, err := ioutil.TempFile("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -1816,7 +1816,7 @@ func TestReadConfigPaths_file(t *testing.T) { } func TestReadConfigPaths_dir(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/agent/http_test.go b/command/agent/http_test.go index a1209b4b71..135b771218 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -77,12 +77,12 @@ func TestHTTPServer_UnixSocket(t *testing.T) { t.SkipNow() } - tempDir, err := ioutil.TempDir("", "consul") + tempDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } defer os.RemoveAll(tempDir) - socket := filepath.Join(tempDir, "test.sock") + socket := filepath.Join(tempDir, t.Name()+".sock") dir, srv := makeHTTPServerWithConfig(t, func(c *Config) { c.Addresses.HTTP = "unix://" + socket @@ -139,12 +139,12 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) { t.SkipNow() } - tempDir, err := ioutil.TempDir("", "consul") + tempDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } defer os.RemoveAll(tempDir) - socket := filepath.Join(tempDir, "test.sock") + socket := filepath.Join(tempDir, t.Name()+".sock") // Create a regular file at the socket path if err := ioutil.WriteFile(socket, []byte("hello world"), 0644); err != nil { diff --git a/command/agent/keyring_test.go b/command/agent/keyring_test.go index 0a40092a93..689e3c50b1 100644 --- a/command/agent/keyring_test.go +++ b/command/agent/keyring_test.go @@ -81,7 +81,7 @@ func TestAgent_InitKeyring(t *testing.T) { key2 := "4leC33rgtXKIVUr9Nr0snQ==" expected := fmt.Sprintf(`["%s"]`, key1) - dir, err := ioutil.TempDir("", "consul") + dir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/agent/ui_endpoint_test.go b/command/agent/ui_endpoint_test.go index 9aaa536ae5..e23ffae140 100644 --- a/command/agent/ui_endpoint_test.go +++ b/command/agent/ui_endpoint_test.go @@ -20,7 +20,7 @@ import ( func TestUiIndex(t *testing.T) { // Make a test dir to serve UI files - uiDir, err := ioutil.TempDir("", "consul") + uiDir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/agent/util_test.go b/command/agent/util_test.go index 043205284d..4f016f7b68 100644 --- a/command/agent/util_test.go +++ b/command/agent/util_test.go @@ -37,7 +37,7 @@ func TestSetFilePermissions(t *testing.T) { if runtime.GOOS == "windows" { t.SkipNow() } - tempFile, err := ioutil.TempFile("", "consul") + tempFile, err := ioutil.TempFile("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/configtest_test.go b/command/configtest_test.go index 2db93c283f..43a9a4bd03 100644 --- a/command/configtest_test.go +++ b/command/configtest_test.go @@ -25,7 +25,7 @@ func TestConfigTestCommand_implements(t *testing.T) { } func TestConfigTestCommandFailOnEmptyFile(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "consul") + tmpFile, err := ioutil.TempFile("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -43,7 +43,7 @@ func TestConfigTestCommandFailOnEmptyFile(t *testing.T) { } func TestConfigTestCommandSucceedOnEmptyDir(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -61,7 +61,7 @@ func TestConfigTestCommandSucceedOnEmptyDir(t *testing.T) { } func TestConfigTestCommandSucceedOnMinimalConfigFile(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -85,7 +85,7 @@ func TestConfigTestCommandSucceedOnMinimalConfigFile(t *testing.T) { } func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -108,7 +108,7 @@ func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) { } func TestConfigTestCommandSucceedOnConfigDirWithEmptyFile(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/command/kv_put_test.go b/command/kv_put_test.go index befc440a21..f4609d25a7 100644 --- a/command/kv_put_test.go +++ b/command/kv_put_test.go @@ -179,7 +179,7 @@ func TestKVPutCommand_File(t *testing.T) { ui, c := testKVPutCommand(t) - f, err := ioutil.TempFile("", "kv-put-command-file") + f, err := ioutil.TempFile("", t.Name()+"-kv-put-command-file") if err != nil { t.Fatalf("err: %#v", err) } diff --git a/command/snapshot_inspect_test.go b/command/snapshot_inspect_test.go index e07f1e241c..851200a8f2 100644 --- a/command/snapshot_inspect_test.go +++ b/command/snapshot_inspect_test.go @@ -73,7 +73,7 @@ func TestSnapshotInspectCommand_Run(t *testing.T) { defer srv.Shutdown() waitForLeader(t, srv.httpAddr) - dir, err := ioutil.TempDir("", "snapshot") + dir, err := ioutil.TempDir("", t.Name()+"-snapshot") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/snapshot_restore_test.go b/command/snapshot_restore_test.go index f5e80eecf5..ad65c188a8 100644 --- a/command/snapshot_restore_test.go +++ b/command/snapshot_restore_test.go @@ -75,7 +75,7 @@ func TestSnapshotRestoreCommand_Run(t *testing.T) { ui, c := testSnapshotRestoreCommand(t) - dir, err := ioutil.TempDir("", "snapshot") + dir, err := ioutil.TempDir("", t.Name()+"-snapshot") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/snapshot_save_test.go b/command/snapshot_save_test.go index 71e32abc36..239e07c185 100644 --- a/command/snapshot_save_test.go +++ b/command/snapshot_save_test.go @@ -74,7 +74,7 @@ func TestSnapshotSaveCommand_Run(t *testing.T) { ui, c := testSnapshotSaveCommand(t) - dir, err := ioutil.TempDir("", "snapshot") + dir, err := ioutil.TempDir("", t.Name()+"-snapshot") if err != nil { t.Fatalf("err: %v", err) } diff --git a/command/util_test.go b/command/util_test.go index 26d963a3bb..66c441427d 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -67,7 +67,7 @@ func testAgentWithConfigReload(t *testing.T, cb func(c *agent.Config), reloadCh cb(conf) } - dir, err := ioutil.TempDir("", "agent") + dir, err := ioutil.TempDir("", t.Name()+"-agent") if err != nil { t.Fatalf(fmt.Sprintf("err: %v", err)) } diff --git a/command/validate_test.go b/command/validate_test.go index 3abdb0fff5..a58ac51be8 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -25,7 +25,7 @@ func TestValidateCommand_implements(t *testing.T) { } func TestValidateCommandFailOnEmptyFile(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "consul") + tmpFile, err := ioutil.TempFile("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -41,7 +41,7 @@ func TestValidateCommandFailOnEmptyFile(t *testing.T) { } func TestValidateCommandSucceedOnEmptyDir(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -57,7 +57,7 @@ func TestValidateCommandSucceedOnEmptyDir(t *testing.T) { } func TestValidateCommandSucceedOnMinimalConfigFile(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -79,7 +79,7 @@ func TestValidateCommandSucceedOnMinimalConfigFile(t *testing.T) { } func TestValidateCommandSucceedOnMinimalConfigDir(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -100,7 +100,7 @@ func TestValidateCommandSucceedOnMinimalConfigDir(t *testing.T) { } func TestValidateCommandSucceedOnConfigDirWithEmptyFile(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } @@ -121,7 +121,7 @@ func TestValidateCommandSucceedOnConfigDirWithEmptyFile(t *testing.T) { } func TestValidateCommandQuiet(t *testing.T) { - td, err := ioutil.TempDir("", "consul") + td, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %s", err) } diff --git a/consul/server_test.go b/consul/server_test.go index 3da390906b..e79762fb33 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -24,7 +24,7 @@ func getPort() int { } func tmpDir(t *testing.T) string { - dir, err := ioutil.TempDir("", "consul") + dir, err := ioutil.TempDir("", t.Name()+"-consul") if err != nil { t.Fatalf("err: %v", err) } diff --git a/snapshot/snapshot_test.go b/snapshot/snapshot_test.go index 45e0b3297e..1883c0f84a 100644 --- a/snapshot/snapshot_test.go +++ b/snapshot/snapshot_test.go @@ -126,7 +126,7 @@ func makeRaft(t *testing.T, dir string) (*raft.Raft, *MockFSM) { } func TestSnapshot(t *testing.T) { - dir, err := ioutil.TempDir("", "snapshot") + dir, err := ioutil.TempDir("", t.Name()+"-snapshot") if err != nil { t.Fatalf("err: %v", err) } @@ -238,7 +238,7 @@ func TestSnapshot_BadVerify(t *testing.T) { } func TestSnapshot_BadRestore(t *testing.T) { - dir, err := ioutil.TempDir("", "snapshot") + dir, err := ioutil.TempDir("", t.Name()+"-snapshot") if err != nil { t.Fatalf("err: %v", err) } diff --git a/testutil/server.go b/testutil/server.go index 6cf8ccb769..2eb4395c6b 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -173,26 +173,26 @@ type TestServer struct { // NewTestServer is an easy helper method to create a new Consul // test server with the most basic configuration. -func NewTestServer() (*TestServer, error) { - return NewTestServerConfig(nil) +func NewTestServer(name string) (*TestServer, error) { + return NewTestServerConfig(name, nil) } // NewTestServerConfig creates a new TestServer, and makes a call to an optional // callback function to modify the configuration. If there is an error // configuring or starting the server, the server will NOT be running when the // function returns (thus you do not need to stop it). -func NewTestServerConfig(cb ServerConfigCallback) (*TestServer, error) { +func NewTestServerConfig(name string, cb ServerConfigCallback) (*TestServer, error) { if path, err := exec.LookPath("consul"); err != nil || path == "" { return nil, fmt.Errorf("consul not found on $PATH - download and install " + "consul or skip this test") } - dataDir, err := ioutil.TempDir("", "consul") + dataDir, err := ioutil.TempDir("", name+"-consul") if err != nil { return nil, errors.Wrap(err, "failed creating tempdir") } - configFile, err := ioutil.TempFile(dataDir, "config") + configFile, err := ioutil.TempFile(dataDir, name+"-config") if err != nil { defer os.RemoveAll(dataDir) return nil, errors.Wrap(err, "failed creating temp config")