19081: Disable singularity env var eval behavior if possible.
[arvados.git] / lib / crunchrun / singularity_test.go
index a1263da3215ad6d07d7fcf2db444c06528d7dd72..bad2abef33efc25ec6e04833d58b22029694e720 100644 (file)
@@ -27,3 +27,26 @@ func (s *singularitySuite) SetUpSuite(c *C) {
                c.Assert(err, IsNil)
        }
 }
+
+var _ = Suite(&singularityStubSuite{})
+
+// singularityStubSuite tests don't really invoke singularity, so we
+// can run them even if singularity is not installed.
+type singularityStubSuite struct{}
+
+func (s *singularityStubSuite) TestSingularityExecArgs(c *C) {
+       e, err := newSingularityExecutor(c.Logf)
+       c.Assert(err, IsNil)
+       err = e.Create(containerSpec{
+               WorkingDir:      "/WorkingDir",
+               Env:             map[string]string{"FOO": "bar"},
+               BindMounts:      map[string]bindmount{"/mnt": {HostPath: "/hostpath", ReadOnly: true}},
+               EnableNetwork:   false,
+               CUDADeviceCount: 3,
+       })
+       c.Check(err, IsNil)
+       e.imageFilename = "/fake/image.sif"
+       cmd := e.execCmd("./singularity")
+       c.Check(cmd.Args, DeepEquals, []string{"./singularity", "exec", "--containall", "--cleanenv", "--pwd", "/WorkingDir", "--net", "--network=none", "--nv", "--bind", "/hostpath:/mnt:ro", "/fake/image.sif"})
+       c.Check(cmd.Env, DeepEquals, []string{"SINGULARITYENV_FOO=bar", "SINGULARITY_NO_EVAL=1"})
+}