12308: Add "arvados-client mount" command via cgofuse.
[arvados.git] / lib / mount / command_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package mount
6
7 import (
8         "bytes"
9         "io/ioutil"
10         "os"
11         "time"
12
13         check "gopkg.in/check.v1"
14 )
15
16 var _ = check.Suite(&CmdSuite{})
17
18 type CmdSuite struct {
19         mnt string
20 }
21
22 func (s *CmdSuite) SetUpTest(c *check.C) {
23         tmpdir, err := ioutil.TempDir("", "")
24         c.Assert(err, check.IsNil)
25         s.mnt = tmpdir
26 }
27
28 func (s *CmdSuite) TearDownTest(c *check.C) {
29         c.Check(os.RemoveAll(s.mnt), check.IsNil)
30 }
31
32 func (s *CmdSuite) TestMount(c *check.C) {
33         exited := make(chan int)
34         stdin := bytes.NewBufferString("stdin")
35         stdout := bytes.NewBuffer(nil)
36         stderr := bytes.NewBuffer(nil)
37         mountCmd := cmd{ready: make(chan struct{})}
38         ready := false
39         go func() {
40                 exited <- mountCmd.RunCommand("test mount", []string{"--experimental", s.mnt}, stdin, stdout, stderr)
41         }()
42         go func() {
43                 <-mountCmd.ready
44                 ready = true
45                 ok := mountCmd.Unmount()
46                 c.Check(ok, check.Equals, true)
47         }()
48         select {
49         case <-time.After(5 * time.Second):
50                 c.Fatal("timed out")
51         case errCode, ok := <-exited:
52                 c.Check(ok, check.Equals, true)
53                 c.Check(errCode, check.Equals, 0)
54         }
55         c.Check(ready, check.Equals, true)
56         c.Check(stdout.String(), check.Equals, "")
57         // stdin should not have been read
58         c.Check(stdin.String(), check.Equals, "stdin")
59 }