1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 check "gopkg.in/check.v1"
16 // Importing arvadostest would be an import cycle, so these
17 // fixtures are duplicated here [until fs moves to a separate
19 fixtureActiveToken = "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi"
20 fixtureAProjectUUID = "zzzzz-j7d0g-v955i6s2oi1cbso"
21 fixtureFooAndBarFilesInDirUUID = "zzzzz-4zz18-foonbarfilesdir"
22 fixtureFooCollectionName = "zzzzz-4zz18-fy296fx3hot09f7 added sometime"
23 fixtureFooCollectionPDH = "1f4b0bc7583c2a7f9102c395f4ffc5e3+45"
24 fixtureFooCollection = "zzzzz-4zz18-fy296fx3hot09f7"
25 fixtureNonexistentCollection = "zzzzz-4zz18-totallynotexist"
26 fixtureBlobSigningKey = "zfhgfenhffzltr9dixws36j1yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc"
27 fixtureBlobSigningTTL = 336 * time.Hour
30 var _ = check.Suite(&SiteFSSuite{})
32 type SiteFSSuite struct {
38 func (s *SiteFSSuite) SetUpTest(c *check.C) {
40 APIHost: os.Getenv("ARVADOS_API_HOST"),
41 AuthToken: fixtureActiveToken,
44 s.kc = &keepClientStub{
45 blocks: map[string][]byte{
46 "3858f62230ac3c915f300c664312c63f": []byte("foobar"),
48 sigkey: fixtureBlobSigningKey,
49 sigttl: fixtureBlobSigningTTL,
50 authToken: fixtureActiveToken,
52 s.fs = s.client.SiteFileSystem(s.kc)
55 func (s *SiteFSSuite) TestHttpFileSystemInterface(c *check.C) {
56 _, ok := s.fs.(http.FileSystem)
57 c.Check(ok, check.Equals, true)
60 func (s *SiteFSSuite) TestByIDEmpty(c *check.C) {
61 f, err := s.fs.Open("/by_id")
62 c.Assert(err, check.IsNil)
63 fis, err := f.Readdir(-1)
64 c.Check(err, check.IsNil)
65 c.Check(len(fis), check.Equals, 0)
68 func (s *SiteFSSuite) TestByUUIDAndPDH(c *check.C) {
69 f, err := s.fs.Open("/by_id")
70 c.Assert(err, check.IsNil)
71 fis, err := f.Readdir(-1)
72 c.Check(err, check.IsNil)
73 c.Check(len(fis), check.Equals, 0)
75 err = s.fs.Mkdir("/by_id/"+fixtureFooCollection, 0755)
76 c.Check(err, check.Equals, os.ErrExist)
78 f, err = s.fs.Open("/by_id/" + fixtureNonexistentCollection)
79 c.Assert(err, check.Equals, os.ErrNotExist)
81 for _, path := range []string{
83 fixtureFooCollectionPDH,
84 fixtureAProjectUUID + "/" + fixtureFooCollectionName,
86 f, err = s.fs.Open("/by_id/" + path)
87 c.Assert(err, check.IsNil)
88 fis, err = f.Readdir(-1)
89 c.Assert(err, check.IsNil)
91 for _, fi := range fis {
92 names = append(names, fi.Name())
94 c.Check(names, check.DeepEquals, []string{"foo"})
97 f, err = s.fs.Open("/by_id/" + fixtureAProjectUUID + "/A Subproject/baz_file")
98 c.Assert(err, check.IsNil)
99 fis, err = f.Readdir(-1)
100 c.Assert(err, check.IsNil)
102 for _, fi := range fis {
103 names = append(names, fi.Name())
105 c.Check(names, check.DeepEquals, []string{"baz"})
107 _, err = s.fs.OpenFile("/by_id/"+fixtureNonexistentCollection, os.O_RDWR|os.O_CREATE, 0755)
108 c.Check(err, check.Equals, ErrInvalidArgument)
109 err = s.fs.Rename("/by_id/"+fixtureFooCollection, "/by_id/beep")
110 c.Check(err, check.Equals, ErrInvalidArgument)
111 err = s.fs.Rename("/by_id/"+fixtureFooCollection+"/foo", "/by_id/beep")
112 c.Check(err, check.Equals, ErrInvalidArgument)
113 _, err = s.fs.Stat("/by_id/beep")
114 c.Check(err, check.Equals, os.ErrNotExist)
115 err = s.fs.Rename("/by_id/"+fixtureFooCollection+"/foo", "/by_id/"+fixtureFooCollection+"/bar")
116 c.Check(err, check.IsNil)
118 err = s.fs.Rename("/by_id", "/beep")
119 c.Check(err, check.Equals, ErrInvalidArgument)