mirror of https://github.com/status-im/consul.git
test: include test name in temp file/dir
This helps identifying hanging tests by looking at the process list.
This commit is contained in:
parent
f26c4f62a5
commit
3522a41bad
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue