18691: Add groups.frozen_by_uuid attribute.
[arvados.git] / lib / crunchrun / singularity_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package crunchrun
6
7 import (
8         "os/exec"
9
10         . "gopkg.in/check.v1"
11 )
12
13 var _ = Suite(&singularitySuite{})
14
15 type singularitySuite struct {
16         executorSuite
17 }
18
19 func (s *singularitySuite) SetUpSuite(c *C) {
20         _, err := exec.LookPath("singularity")
21         if err != nil {
22                 c.Skip("looks like singularity is not installed")
23         }
24         s.newExecutor = func(c *C) {
25                 var err error
26                 s.executor, err = newSingularityExecutor(c.Logf)
27                 c.Assert(err, IsNil)
28         }
29 }
30
31 var _ = Suite(&singularityStubSuite{})
32
33 // singularityStubSuite tests don't really invoke singularity, so we
34 // can run them even if singularity is not installed.
35 type singularityStubSuite struct{}
36
37 func (s *singularityStubSuite) TestSingularityExecArgs(c *C) {
38         e, err := newSingularityExecutor(c.Logf)
39         c.Assert(err, IsNil)
40         err = e.Create(containerSpec{
41                 WorkingDir:      "/WorkingDir",
42                 Env:             map[string]string{"FOO": "bar"},
43                 BindMounts:      map[string]bindmount{"/mnt": {HostPath: "/hostpath", ReadOnly: true}},
44                 EnableNetwork:   false,
45                 CUDADeviceCount: 3,
46         })
47         c.Check(err, IsNil)
48         e.imageFilename = "/fake/image.sif"
49         cmd := e.execCmd("./singularity")
50         c.Check(cmd.Args, DeepEquals, []string{"./singularity", "exec", "--containall", "--cleanenv", "--pwd", "/WorkingDir", "--net", "--network=none", "--nv", "--bind", "/hostpath:/mnt:ro", "/fake/image.sif"})
51         c.Check(cmd.Env, DeepEquals, []string{"SINGULARITYENV_FOO=bar"})
52 }