commit 4896ea964770789632b4d5446a573d9c6f367319 Author: Pete Zaitcev Date: Wed Jun 22 22:25:00 2016 -0600 Force /var/tmp as the test directory because of xattr We use xattr a lot. But we don't want to use the current directory because... no reason. It just seems wrong to pollute a source diretory with test files. Let's use the root as next bet for the systems where /tmp is mounted (Fedora 23, for example). diff --git a/go/objectserver/auditor_test.go b/go/objectserver/auditor_test.go index 8dd27ed..f899553 100644 --- a/go/objectserver/auditor_test.go +++ b/go/objectserver/auditor_test.go @@ -32,7 +32,7 @@ import ( ) func TestAuditHashPasses(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "fffffffffffffffffffffffffffffabc", "12345.data")) @@ -127,7 +127,7 @@ func TestAuditHashInvalidContentLength(t *testing.T) { } func TestAuditHashBadHash(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "fffffffffffffffffffffffffffffabc", "12345.data")) @@ -225,7 +225,7 @@ func TestAuditSuffixNotDir(t *testing.T) { } func TestAuditSuffixPasses(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "abc", "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "abc", "fffffffffffffffffffffffffffffabc", "12345.data")) @@ -276,7 +276,7 @@ func TestAuditPartitionNotDir(t *testing.T) { } func TestAuditPartitionPasses(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "1", "abc", "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "1", "abc", "fffffffffffffffffffffffffffffabc", "12345.data")) @@ -291,7 +291,7 @@ func TestAuditPartitionPasses(t *testing.T) { } func TestAuditPartitionSkipsBadData(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "1", "abc", "fffffffffffffffffffffffffffffabc"), 0777) os.MkdirAll(filepath.Join(dir, "1", "xyz"), 0777) @@ -323,7 +323,7 @@ func TestAuditDeviceNotDir(t *testing.T) { } func TestAuditDevicePasses(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "sda", "objects", "1", "abc", "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "sda", "objects", "1", "abc", "fffffffffffffffffffffffffffffabc", "12345.data")) @@ -338,7 +338,7 @@ func TestAuditDevicePasses(t *testing.T) { } func TestAuditDeviceSkipsBadData(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "sda", "objects", "1", "abc", "fffffffffffffffffffffffffffffabc"), 0777) os.MkdirAll(filepath.Join(dir, "sda", "objects", "X"), 0777) @@ -354,7 +354,7 @@ func TestAuditDeviceSkipsBadData(t *testing.T) { } func TestAuditDeviceUnmounted(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "sda", "objects", "1"), 0777) auditor := makeAuditor("mount_check", "true") @@ -379,7 +379,7 @@ func TestFinalLog(t *testing.T) { } func TestAuditRun(t *testing.T) { - dir, _ := ioutil.TempDir("", "") + dir, _ := ioutil.TempDir("/var/tmp", "") defer os.RemoveAll(dir) os.MkdirAll(filepath.Join(dir, "sda", "objects", "1", "abc", "fffffffffffffffffffffffffffffabc"), 0777) f, _ := os.Create(filepath.Join(dir, "sda", "objects", "1", "abc", "fffffffffffffffffffffffffffffabc", "12345.data")) diff --git a/go/objectserver/backend_test.go b/go/objectserver/backend_test.go index fbb7ced..9bd05ba 100644 --- a/go/objectserver/backend_test.go +++ b/go/objectserver/backend_test.go @@ -34,7 +34,7 @@ func TestWriteReadMetadata(t *testing.T) { strings.Repeat("la", 5): strings.Repeat("la", 30), strings.Repeat("moo", 500): strings.Repeat("moo", 300), } - testFile, err := ioutil.TempFile("/tmp", "backend_test") + testFile, err := ioutil.TempFile("/var/tmp", "backend_test") defer testFile.Close() defer os.Remove(testFile.Name()) assert.Equal(t, err, nil) diff --git a/go/objectserver/main_test.go b/go/objectserver/main_test.go index a1293c8..f76fb14 100644 --- a/go/objectserver/main_test.go +++ b/go/objectserver/main_test.go @@ -59,7 +59,8 @@ func (t *TestServer) Do(method string, path string, body io.ReadCloser) (*http.R } func makeObjectServer(settings ...string) (*TestServer, error) { - driveRoot, err := ioutil.TempDir("", "") + // We had to embed the whole server into /var/tmp, not nice... + driveRoot, err := ioutil.TempDir("/var/tmp", "") if err != nil { return nil, err } diff --git a/go/objectserver/replicator_test.go b/go/objectserver/replicator_test.go index 4a1b76d..660b1d6 100644 --- a/go/objectserver/replicator_test.go +++ b/go/objectserver/replicator_test.go @@ -248,7 +248,7 @@ func (s *repmanLogSaver) Err(val string) error { func TestGetFile(t *testing.T) { replicator, err := makeReplicator() require.Nil(t, err) - file, err := ioutil.TempFile("", "") + file, err := ioutil.TempFile("/var/tmp", "") assert.Nil(t, err) defer file.Close() defer os.RemoveAll(file.Name()) @@ -290,7 +290,7 @@ func TestGetFileBadFile(t *testing.T) { func TestGetFileBadMetadata(t *testing.T) { replicator, err := makeReplicator() require.Nil(t, err) - file, err := ioutil.TempFile("", "") + file, err := ioutil.TempFile("/var/tmp", "") require.Nil(t, err) defer file.Close() defer os.RemoveAll(file.Name()) diff --git a/go/objectserver/swiftobjeng_test.go b/go/objectserver/swiftobjeng_test.go index 63b1cdd..967d40b 100644 --- a/go/objectserver/swiftobjeng_test.go +++ b/go/objectserver/swiftobjeng_test.go @@ -12,7 +12,7 @@ import ( ) func TestSwiftObjectRoundtrip(t *testing.T) { - driveRoot, err := ioutil.TempDir("", "") + driveRoot, err := ioutil.TempDir("/var/tmp", "") require.Nil(t, err) defer os.RemoveAll(driveRoot) @@ -39,7 +39,7 @@ func TestSwiftObjectRoundtrip(t *testing.T) { } func TestSwiftObjectFailAuditContentLengthWrong(t *testing.T) { - driveRoot, err := ioutil.TempDir("", "") + driveRoot, err := ioutil.TempDir("/var/tmp", "") require.Nil(t, err) defer os.RemoveAll(driveRoot) @@ -58,7 +58,7 @@ func TestSwiftObjectFailAuditContentLengthWrong(t *testing.T) { } func TestSwiftObjectFailAuditBadContentLength(t *testing.T) { - driveRoot, err := ioutil.TempDir("", "") + driveRoot, err := ioutil.TempDir("/var/tmp", "") require.Nil(t, err) defer os.RemoveAll(driveRoot) @@ -95,7 +95,7 @@ func TestSwiftObjectQuarantine(t *testing.T) { } func TestSwiftObjectMultiCopy(t *testing.T) { - driveRoot, err := ioutil.TempDir("", "") + driveRoot, err := ioutil.TempDir("/var/tmp", "") require.Nil(t, err) defer os.RemoveAll(driveRoot) @@ -121,7 +121,7 @@ func TestSwiftObjectMultiCopy(t *testing.T) { } func TestSwiftObjectDelete(t *testing.T) { - driveRoot, err := ioutil.TempDir("", "") + driveRoot, err := ioutil.TempDir("/var/tmp", "") require.Nil(t, err) defer os.RemoveAll(driveRoot) diff --git a/go/probe/base.go b/go/probe/base.go index e507fe8..628c902 100644 --- a/go/probe/base.go +++ b/go/probe/base.go @@ -154,7 +154,9 @@ func NewEnvironment(settings ...string) *Environment { env := &Environment{ring: &FakeRing{devices: nil}} env.hashPrefix, env.hashSuffix, _ = hummingbird.GetHashPrefixAndSuffix() for i := 0; i < 4; i++ { - driveRoot, _ := ioutil.TempDir("", "") + // The NewEnvironment is only called from tests, + // so hardcoding /var/tmp should be acceptable. + driveRoot, _ := ioutil.TempDir("/var/tmp", "") os.MkdirAll(filepath.Join(driveRoot, "sda", "objects"), 0755) ts := httptest.NewServer(nil) u, _ := url.Parse(ts.URL) diff --git a/go/xattr/xattr_test.go b/go/xattr/xattr_test.go index ceb15b4..71d4d81 100644 --- a/go/xattr/xattr_test.go +++ b/go/xattr/xattr_test.go @@ -24,7 +24,7 @@ import ( ) func TestFXattr(t *testing.T) { - fp, err := ioutil.TempFile("", "") + fp, err := ioutil.TempFile("/var/tmp", "") require.Nil(t, err) defer fp.Close() defer os.RemoveAll(fp.Name()) @@ -41,7 +41,7 @@ func TestFXattr(t *testing.T) { } func TestXattr(t *testing.T) { - fp, err := ioutil.TempFile("", "") + fp, err := ioutil.TempFile("/var/tmp", "") require.Nil(t, err) defer fp.Close() defer os.RemoveAll(fp.Name())