1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
12 check "gopkg.in/check.v1"
15 var _ = check.Suite(&SiteFSSuite{})
17 type SiteFSSuite struct {
23 func (s *SiteFSSuite) SetUpTest(c *check.C) {
25 APIHost: os.Getenv("ARVADOS_API_HOST"),
26 AuthToken: arvadostest.ActiveToken,
29 s.kc = &keepClientStub{
30 blocks: map[string][]byte{
31 "3858f62230ac3c915f300c664312c63f": []byte("foobar"),
33 s.fs = s.client.SiteFileSystem(s.kc)
36 func (s *SiteFSSuite) TestHttpFileSystemInterface(c *check.C) {
37 _, ok := s.fs.(http.FileSystem)
38 c.Check(ok, check.Equals, true)
41 func (s *SiteFSSuite) TestByIDEmpty(c *check.C) {
42 f, err := s.fs.Open("/by_id")
43 c.Assert(err, check.IsNil)
44 fis, err := f.Readdir(-1)
45 c.Check(err, check.IsNil)
46 c.Check(len(fis), check.Equals, 0)
49 func (s *SiteFSSuite) TestByUUIDAndPDH(c *check.C) {
50 f, err := s.fs.Open("/by_id")
51 c.Assert(err, check.IsNil)
52 fis, err := f.Readdir(-1)
53 c.Check(err, check.IsNil)
54 c.Check(len(fis), check.Equals, 0)
56 err = s.fs.Mkdir("/by_id/"+arvadostest.FooCollection, 0755)
57 c.Check(err, check.Equals, os.ErrExist)
59 f, err = s.fs.Open("/by_id/" + arvadostest.NonexistentCollection)
60 c.Assert(err, check.Equals, os.ErrNotExist)
62 for _, path := range []string{
63 arvadostest.FooCollection,
65 arvadostest.AProjectUUID + "/" + arvadostest.FooCollectionName,
67 f, err = s.fs.Open("/by_id/" + path)
68 c.Assert(err, check.IsNil)
69 fis, err = f.Readdir(-1)
71 for _, fi := range fis {
72 names = append(names, fi.Name())
74 c.Check(names, check.DeepEquals, []string{"foo"})
77 f, err = s.fs.Open("/by_id/" + arvadostest.AProjectUUID + "/A Subproject/baz_file")
78 c.Assert(err, check.IsNil)
79 fis, err = f.Readdir(-1)
81 for _, fi := range fis {
82 names = append(names, fi.Name())
84 c.Check(names, check.DeepEquals, []string{"baz"})
86 _, err = s.fs.OpenFile("/by_id/"+arvadostest.NonexistentCollection, os.O_RDWR|os.O_CREATE, 0755)
87 c.Check(err, check.Equals, ErrInvalidOperation)
88 err = s.fs.Rename("/by_id/"+arvadostest.FooCollection, "/by_id/beep")
89 c.Check(err, check.Equals, ErrInvalidArgument)
90 err = s.fs.Rename("/by_id/"+arvadostest.FooCollection+"/foo", "/by_id/beep")
91 c.Check(err, check.Equals, ErrInvalidArgument)
92 _, err = s.fs.Stat("/by_id/beep")
93 c.Check(err, check.Equals, os.ErrNotExist)
94 err = s.fs.Rename("/by_id/"+arvadostest.FooCollection+"/foo", "/by_id/"+arvadostest.FooCollection+"/bar")
95 c.Check(err, check.IsNil)
97 err = s.fs.Rename("/by_id", "/beep")
98 c.Check(err, check.Equals, ErrInvalidArgument)