8015: Add arv-mount command line test
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 15 Feb 2016 03:27:24 +0000 (22:27 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 15 Feb 2016 03:27:24 +0000 (22:27 -0500)
services/crunch-run/crunchrun.go
services/crunch-run/crunchrun_test.go

index 665f10767ae2989dffa4f8b9198111fedeffbe01..a6d23abdc202aaeb4b8954236bdfcbf41f94ae40 100644 (file)
@@ -72,6 +72,8 @@ type NewLogWriter func(name string) io.WriteCloser
 
 type RunArvMount func([]string) (*exec.Cmd, error)
 
+type MkTempDir func(string, string) (string, error)
+
 // ThinDockerClient is the minimal Docker client interface used by crunch-run.
 type ThinDockerClient interface {
        StopContainer(id string, timeout int) error
@@ -102,6 +104,7 @@ type ContainerRunner struct {
        LogCollection *CollectionWriter
        LogsPDH       *string
        RunArvMount
+       MkTempDir
        ArvMount      *exec.Cmd
        ArvMountPoint string
        HostOutputDir string
@@ -230,7 +233,7 @@ func (runner *ContainerRunner) ArvMountCmd(arvMountCmd []string) (c *exec.Cmd, e
 }
 
 func (runner *ContainerRunner) SetupMounts() (err error) {
-       runner.ArvMountPoint, err = ioutil.TempDir("", "keep")
+       runner.ArvMountPoint, err = runner.MkTempDir("", "keep")
        if err != nil {
                return fmt.Errorf("While creating keep mount temp dir: %v", err)
        }
@@ -274,7 +277,7 @@ func (runner *ContainerRunner) SetupMounts() (err error) {
                        collectionPaths = append(collectionPaths, src)
                } else if mnt.Kind == "tmp" {
                        if bind == runner.ContainerRecord.OutputPath {
-                               runner.HostOutputDir, err = ioutil.TempDir("", "")
+                               runner.HostOutputDir, err = runner.MkTempDir("", "")
                                if err != nil {
                                        return fmt.Errorf("While creating mount temp dir: %v", err)
                                }
@@ -640,6 +643,7 @@ func NewContainerRunner(api IArvadosClient,
        cr := &ContainerRunner{ArvClient: api, Kc: kc, Docker: docker}
        cr.NewLogWriter = cr.NewArvLogWriter
        cr.RunArvMount = cr.ArvMountCmd
+       cr.MkTempDir = ioutil.TempDir
        cr.LogCollection = &CollectionWriter{kc, nil, sync.Mutex{}}
        cr.ContainerRecord.UUID = containerUUID
        cr.CrunchLog = NewThrottledLogger(cr.NewLogWriter("crunch-run"))
index 48c22a3ab76a301f0acb1b11a4ffe862030ab6f9..bdc24139f2a27910089838bdc2a94ad4be31d1da 100644 (file)
@@ -13,6 +13,7 @@ import (
        . "gopkg.in/check.v1"
        "io"
        "io/ioutil"
+       "os/exec"
        "strings"
        "syscall"
        "testing"
@@ -653,3 +654,35 @@ func (s *TestSuite) TestFullRunSetEnv(c *C) {
 
        c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
 }
+
+type ArvMountCmdLine struct {
+       Cmd []string
+}
+
+func (am *ArvMountCmdLine) ArvMountTest(c []string) (*exec.Cmd, error) {
+       am.Cmd = c
+       return nil, nil
+}
+
+func (s *TestSuite) TestSetupMounts(c *C) {
+       api := &ArvTestClient{}
+       kc := &KeepTestClient{}
+       cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
+       am := &ArvMountCmdLine{}
+       cr.RunArvMount = am.ArvMountTest
+
+       i := 0
+       cr.MkTempDir = func(string, string) (string, error) {
+               i += 1
+               return fmt.Sprintf("/tmp/mktmpdir%v", i), nil
+       }
+
+       cr.ContainerRecord.Mounts = make(map[string]Mount)
+       cr.ContainerRecord.Mounts["/tmp"] = Mount{Kind: "tmp"}
+       cr.OutputPath = "/tmp"
+
+       err := cr.SetupMounts()
+       c.Check(err, IsNil)
+       c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
+       c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir2:/tmp"})
+}