Skip to content

Commit

Permalink
test: include test name in temp file/dir
Browse files Browse the repository at this point in the history
This helps identifying hanging tests by looking
at the process list.
  • Loading branch information
magiconair committed May 12, 2017
1 parent f26c4f6 commit 3522a41
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion api/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions command/agent/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/agent/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions command/configtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/kv_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/snapshot_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/snapshot_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/snapshot_save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion command/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
12 changes: 6 additions & 6 deletions command/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion consul/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit 3522a41

Please sign in to comment.