1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.arvados.org/arvados.git/sdk/go/arvadostest"
15 check "gopkg.in/check.v1"
18 var _ = check.Suite(&CmdSuite{})
20 type CmdSuite struct {
24 func (s *CmdSuite) SetUpTest(c *check.C) {
25 tmpdir, err := ioutil.TempDir("", "")
26 c.Assert(err, check.IsNil)
30 func (s *CmdSuite) TearDownTest(c *check.C) {
31 c.Check(os.RemoveAll(s.mnt), check.IsNil)
34 func (s *CmdSuite) TestMount(c *check.C) {
35 exited := make(chan int)
36 stdin := bytes.NewBufferString("stdin")
37 stdout := bytes.NewBuffer(nil)
38 stderr := bytes.NewBuffer(nil)
39 mountCmd := mountCommand{ready: make(chan struct{})}
42 exited <- mountCmd.RunCommand("test mount", []string{"--experimental", s.mnt}, stdin, stdout, stderr)
48 f, err := os.Open(s.mnt + "/by_id/" + arvadostest.FooCollection)
49 if c.Check(err, check.IsNil) {
50 dirnames, err := f.Readdirnames(-1)
51 c.Check(err, check.IsNil)
52 c.Check(dirnames, check.DeepEquals, []string{"foo"})
56 buf, err := ioutil.ReadFile(s.mnt + "/by_id/" + arvadostest.FooCollection + "/.arvados#collection")
57 if c.Check(err, check.IsNil) {
58 var m map[string]interface{}
59 err = json.Unmarshal(buf, &m)
60 c.Check(err, check.IsNil)
61 c.Check(m["manifest_text"], check.Matches, `\. acbd.* 0:3:foo\n`)
64 _, err = os.Open(s.mnt + "/by_id/zzzzz-4zz18-does-not-exist")
65 c.Check(os.IsNotExist(err), check.Equals, true)
67 ok := mountCmd.Unmount()
68 c.Check(ok, check.Equals, true)
71 case <-time.After(5 * time.Second):
73 case errCode, ok := <-exited:
74 c.Check(ok, check.Equals, true)
75 c.Check(errCode, check.Equals, 0)
77 c.Check(ready, check.Equals, true)
78 c.Check(stdout.String(), check.Equals, "")
79 // stdin should not have been read
80 c.Check(stdin.String(), check.Equals, "stdin")