13111: Merge branch 'master' into 12308-go-fuse
[arvados.git] / sdk / go / arvados / fs_project_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvados
6
7 import (
8         "bytes"
9         "encoding/json"
10         "io"
11         "os"
12
13         check "gopkg.in/check.v1"
14 )
15
16 type spiedRequest struct {
17         method string
18         path   string
19         params map[string]interface{}
20 }
21
22 type spyingClient struct {
23         *Client
24         calls []spiedRequest
25 }
26
27 func (sc *spyingClient) RequestAndDecode(dst interface{}, method, path string, body io.Reader, params interface{}) error {
28         var paramsCopy map[string]interface{}
29         var buf bytes.Buffer
30         json.NewEncoder(&buf).Encode(params)
31         json.NewDecoder(&buf).Decode(&paramsCopy)
32         sc.calls = append(sc.calls, spiedRequest{
33                 method: method,
34                 path:   path,
35                 params: paramsCopy,
36         })
37         return sc.Client.RequestAndDecode(dst, method, path, body, params)
38 }
39
40 func (s *SiteFSSuite) TestHomeProject(c *check.C) {
41         f, err := s.fs.Open("/home")
42         c.Assert(err, check.IsNil)
43         fis, err := f.Readdir(-1)
44         c.Check(len(fis), check.Not(check.Equals), 0)
45
46         ok := false
47         for _, fi := range fis {
48                 c.Check(fi.Name(), check.Not(check.Equals), "")
49                 if fi.Name() == "Unrestricted public data" {
50                         ok = true
51                 }
52         }
53         c.Check(ok, check.Equals, true)
54
55         f, err = s.fs.Open("/home/Unrestricted public data/..")
56         c.Assert(err, check.IsNil)
57         fi, err := f.Stat()
58         c.Check(err, check.IsNil)
59         c.Check(fi.IsDir(), check.Equals, true)
60         c.Check(fi.Name(), check.Equals, "home")
61
62         f, err = s.fs.Open("/home/Unrestricted public data/Subproject in anonymous accessible project")
63         c.Check(err, check.IsNil)
64         fi, err = f.Stat()
65         c.Check(err, check.IsNil)
66         c.Check(fi.IsDir(), check.Equals, true)
67
68         for _, nx := range []string{
69                 "/home/A Project",
70                 "/home/A Project/does not exist",
71                 "/home/Unrestricted public data/does not exist",
72         } {
73                 c.Log(nx)
74                 f, err = s.fs.Open(nx)
75                 c.Check(err, check.NotNil)
76                 c.Check(os.IsNotExist(err), check.Equals, true)
77         }
78 }