1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
14 check "gopkg.in/check.v1"
17 var _ = check.Suite(&CollectionFSSuite{})
19 type CollectionFSSuite struct {
25 func (s *CollectionFSSuite) SetUpTest(c *check.C) {
26 s.client = NewClientFromEnv()
27 err := s.client.RequestAndDecode(&s.coll, "GET", "arvados/v1/collections/"+arvadostest.FooAndBarFilesInDirUUID, nil, nil)
28 c.Assert(err, check.IsNil)
29 s.fs = s.coll.FileSystem(s.client, nil)
32 func (s *CollectionFSSuite) TestReaddirFull(c *check.C) {
33 f, err := s.fs.Open("/dir1")
34 c.Assert(err, check.IsNil)
37 c.Assert(err, check.IsNil)
38 c.Check(st.Size(), check.Equals, int64(2))
39 c.Check(st.IsDir(), check.Equals, true)
41 fis, err := f.Readdir(0)
42 c.Check(err, check.IsNil)
43 c.Check(len(fis), check.Equals, 2)
45 c.Check(fis[0].Size(), check.Equals, int64(3))
49 func (s *CollectionFSSuite) TestReaddirLimited(c *check.C) {
50 f, err := s.fs.Open("./dir1")
51 c.Assert(err, check.IsNil)
53 fis, err := f.Readdir(1)
54 c.Check(err, check.IsNil)
55 c.Check(len(fis), check.Equals, 1)
57 c.Check(fis[0].Size(), check.Equals, int64(3))
60 fis, err = f.Readdir(1)
61 c.Check(err, check.Equals, io.EOF)
62 c.Check(len(fis), check.Equals, 1)
64 c.Check(fis[0].Size(), check.Equals, int64(3))
67 fis, err = f.Readdir(1)
68 c.Check(len(fis), check.Equals, 0)
69 c.Check(err, check.NotNil)
70 c.Check(err, check.Equals, io.EOF)
72 f, err = s.fs.Open("dir1")
73 c.Assert(err, check.IsNil)
74 fis, err = f.Readdir(1)
75 c.Check(len(fis), check.Equals, 1)
76 c.Assert(err, check.IsNil)
77 fis, err = f.Readdir(2)
78 c.Check(len(fis), check.Equals, 1)
79 c.Assert(err, check.Equals, io.EOF)
80 fis, err = f.Readdir(2)
81 c.Check(len(fis), check.Equals, 0)
82 c.Assert(err, check.Equals, io.EOF)
85 func (s *CollectionFSSuite) TestPathMunge(c *check.C) {
86 for _, path := range []string{".", "/", "./", "///", "/../", "/./.."} {
87 f, err := s.fs.Open(path)
88 c.Assert(err, check.IsNil)
91 c.Assert(err, check.IsNil)
92 c.Check(st.Size(), check.Equals, int64(1))
93 c.Check(st.IsDir(), check.Equals, true)
95 for _, path := range []string{"/dir1", "dir1", "./dir1", "///dir1//.//", "../dir1/../dir1/"} {
97 f, err := s.fs.Open(path)
98 c.Assert(err, check.IsNil)
101 c.Assert(err, check.IsNil)
102 c.Check(st.Size(), check.Equals, int64(2))
103 c.Check(st.IsDir(), check.Equals, true)
107 func (s *CollectionFSSuite) TestNotExist(c *check.C) {
108 for _, path := range []string{"/no", "no", "./no", "n/o", "/n/o"} {
109 f, err := s.fs.Open(path)
110 c.Assert(f, check.IsNil)
111 c.Assert(err, check.NotNil)
112 c.Assert(os.IsNotExist(err), check.Equals, true)
116 func (s *CollectionFSSuite) TestOpenFile(c *check.C) {
117 c.Skip("cannot test files with nil keepclient")
119 f, err := s.fs.Open("/foo.txt")
120 c.Assert(err, check.IsNil)
122 c.Assert(err, check.IsNil)
123 c.Check(st.Size(), check.Equals, int64(3))
126 // Gocheck boilerplate
127 func Test(t *testing.T) {