9581: add json config file handling to slurm dispatcher.
[arvados.git] / services / datamanager / datamanager_test.go
index 523bbf1c8512ce3cb178d7a4cddeab25cc82eb4f..0ff6b777344d2f5377cc984b5c3f3496d7fcdc13 100644 (file)
@@ -12,11 +12,11 @@ import (
        "net/http"
        "os"
        "os/exec"
+       "path"
        "regexp"
        "strings"
        "testing"
        "time"
-       "path"
 )
 
 var arv arvadosclient.ArvadosClient
@@ -538,34 +538,31 @@ func TestPutAndGetBlocks_NoErrorDuringSingleRun(t *testing.T) {
        testOldBlocksNotDeletedOnDataManagerError(t, "", "", false, false)
 }
 
-func createBadPath(t *testing.T) (badpath string) {
-       tempdir, err := ioutil.TempDir("", "bad")
-       if err != nil {
-               t.Fatalf("Could not create temporary directory for bad path: %v", err)
-       }
-       badpath = path.Join(tempdir, "bad")
-       return
-}
-
-func destroyBadPath(t *testing.T, badpath string) () {
-       tempdir := path.Join(badpath, "..")
-       err := os.Remove(tempdir)
+func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadWriteTo(t *testing.T) {
+       badpath, err := arvadostest.CreateBadPath()
        if err != nil {
-               t.Fatalf("Could not remove bad path temporary directory %v: %v", tempdir, err)
-               return
+               t.Fatalf(err.Error())
        }
-       return
-}
-
-func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadWriteTo(t *testing.T) {
-       badpath := createBadPath(t)
-       defer destroyBadPath(t, badpath)
+       defer func() {
+               err = arvadostest.DestroyBadPath(badpath)
+               if err != nil {
+                       t.Fatalf(err.Error())
+               }
+       }()
        testOldBlocksNotDeletedOnDataManagerError(t, path.Join(badpath, "writetofile"), "", true, true)
 }
 
 func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadHeapProfileFilename(t *testing.T) {
-       badpath := createBadPath(t)
-       defer destroyBadPath(t, badpath)
+       badpath, err := arvadostest.CreateBadPath()
+       if err != nil {
+               t.Fatalf(err.Error())
+       }
+       defer func() {
+               err = arvadostest.DestroyBadPath(badpath)
+               if err != nil {
+                       t.Fatalf(err.Error())
+               }
+       }()
        testOldBlocksNotDeletedOnDataManagerError(t, "", path.Join(badpath, "heapprofilefile"), true, true)
 }