1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 check "gopkg.in/check.v1"
15 // Importing arvadostest would be an import cycle, so these
16 // fixtures are duplicated here [until fs moves to a separate
18 fixtureActiveToken = "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi"
19 fixtureAProjectUUID = "zzzzz-j7d0g-v955i6s2oi1cbso"
20 fixtureFooAndBarFilesInDirUUID = "zzzzz-4zz18-foonbarfilesdir"
21 fixtureFooCollectionName = "zzzzz-4zz18-fy296fx3hot09f7 added sometime"
22 fixtureFooCollectionPDH = "1f4b0bc7583c2a7f9102c395f4ffc5e3+45"
23 fixtureFooCollection = "zzzzz-4zz18-fy296fx3hot09f7"
24 fixtureNonexistentCollection = "zzzzz-4zz18-totallynotexist"
27 var _ = check.Suite(&SiteFSSuite{})
29 type SiteFSSuite struct {
35 func (s *SiteFSSuite) SetUpTest(c *check.C) {
37 APIHost: os.Getenv("ARVADOS_API_HOST"),
38 AuthToken: fixtureActiveToken,
41 s.kc = &keepClientStub{
42 blocks: map[string][]byte{
43 "3858f62230ac3c915f300c664312c63f": []byte("foobar"),
45 s.fs = s.client.SiteFileSystem(s.kc)
48 func (s *SiteFSSuite) TestHttpFileSystemInterface(c *check.C) {
49 _, ok := s.fs.(http.FileSystem)
50 c.Check(ok, check.Equals, true)
53 func (s *SiteFSSuite) TestByIDEmpty(c *check.C) {
54 f, err := s.fs.Open("/by_id")
55 c.Assert(err, check.IsNil)
56 fis, err := f.Readdir(-1)
57 c.Check(err, check.IsNil)
58 c.Check(len(fis), check.Equals, 0)
61 func (s *SiteFSSuite) TestByUUIDAndPDH(c *check.C) {
62 f, err := s.fs.Open("/by_id")
63 c.Assert(err, check.IsNil)
64 fis, err := f.Readdir(-1)
65 c.Check(err, check.IsNil)
66 c.Check(len(fis), check.Equals, 0)
68 err = s.fs.Mkdir("/by_id/"+fixtureFooCollection, 0755)
69 c.Check(err, check.Equals, os.ErrExist)
71 f, err = s.fs.Open("/by_id/" + fixtureNonexistentCollection)
72 c.Assert(err, check.Equals, os.ErrNotExist)
74 for _, path := range []string{
76 fixtureFooCollectionPDH,
77 fixtureAProjectUUID + "/" + fixtureFooCollectionName,
79 f, err = s.fs.Open("/by_id/" + path)
80 c.Assert(err, check.IsNil)
81 fis, err = f.Readdir(-1)
83 for _, fi := range fis {
84 names = append(names, fi.Name())
86 c.Check(names, check.DeepEquals, []string{"foo"})
89 f, err = s.fs.Open("/by_id/" + fixtureAProjectUUID + "/A Subproject/baz_file")
90 c.Assert(err, check.IsNil)
91 fis, err = f.Readdir(-1)
93 for _, fi := range fis {
94 names = append(names, fi.Name())
96 c.Check(names, check.DeepEquals, []string{"baz"})
98 _, err = s.fs.OpenFile("/by_id/"+fixtureNonexistentCollection, os.O_RDWR|os.O_CREATE, 0755)
99 c.Check(err, check.Equals, ErrInvalidOperation)
100 err = s.fs.Rename("/by_id/"+fixtureFooCollection, "/by_id/beep")
101 c.Check(err, check.Equals, ErrInvalidArgument)
102 err = s.fs.Rename("/by_id/"+fixtureFooCollection+"/foo", "/by_id/beep")
103 c.Check(err, check.Equals, ErrInvalidArgument)
104 _, err = s.fs.Stat("/by_id/beep")
105 c.Check(err, check.Equals, os.ErrNotExist)
106 err = s.fs.Rename("/by_id/"+fixtureFooCollection+"/foo", "/by_id/"+fixtureFooCollection+"/bar")
107 c.Check(err, check.IsNil)
109 err = s.fs.Rename("/by_id", "/beep")
110 c.Check(err, check.Equals, ErrInvalidArgument)