13111: Merge branch 'master' into 13111-webdav-projects
[arvados.git] / sdk / go / arvados / fs_site_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         "net/http"
9         "os"
10
11         "git.curoverse.com/arvados.git/sdk/go/arvadostest"
12         check "gopkg.in/check.v1"
13 )
14
15 var _ = check.Suite(&SiteFSSuite{})
16
17 type SiteFSSuite struct {
18         client *Client
19         fs     CustomFileSystem
20         kc     keepClient
21 }
22
23 func (s *SiteFSSuite) SetUpTest(c *check.C) {
24         s.client = &Client{
25                 APIHost:   os.Getenv("ARVADOS_API_HOST"),
26                 AuthToken: arvadostest.ActiveToken,
27                 Insecure:  true,
28         }
29         s.kc = &keepClientStub{
30                 blocks: map[string][]byte{
31                         "3858f62230ac3c915f300c664312c63f": []byte("foobar"),
32                 }}
33         s.fs = s.client.SiteFileSystem(s.kc)
34 }
35
36 func (s *SiteFSSuite) TestHttpFileSystemInterface(c *check.C) {
37         _, ok := s.fs.(http.FileSystem)
38         c.Check(ok, check.Equals, true)
39 }
40
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(len(fis), check.Equals, 0)
46 }
47
48 func (s *SiteFSSuite) TestByUUID(c *check.C) {
49         f, err := s.fs.Open("/by_id")
50         c.Assert(err, check.IsNil)
51         fis, err := f.Readdir(-1)
52         c.Check(err, check.IsNil)
53         c.Check(len(fis), check.Equals, 0)
54
55         err = s.fs.Mkdir("/by_id/"+arvadostest.FooCollection, 0755)
56         c.Check(err, check.Equals, os.ErrExist)
57
58         f, err = s.fs.Open("/by_id/" + arvadostest.NonexistentCollection)
59         c.Assert(err, check.Equals, os.ErrNotExist)
60
61         f, err = s.fs.Open("/by_id/" + arvadostest.FooCollection)
62         c.Assert(err, check.IsNil)
63         fis, err = f.Readdir(-1)
64         var names []string
65         for _, fi := range fis {
66                 names = append(names, fi.Name())
67         }
68         c.Check(names, check.DeepEquals, []string{"foo"})
69
70         _, err = s.fs.OpenFile("/by_id/"+arvadostest.NonexistentCollection, os.O_RDWR|os.O_CREATE, 0755)
71         c.Check(err, check.Equals, ErrInvalidOperation)
72         err = s.fs.Rename("/by_id/"+arvadostest.FooCollection, "/by_id/beep")
73         c.Check(err, check.Equals, ErrInvalidArgument)
74         err = s.fs.Rename("/by_id/"+arvadostest.FooCollection+"/foo", "/by_id/beep")
75         c.Check(err, check.Equals, ErrInvalidArgument)
76         _, err = s.fs.Stat("/by_id/beep")
77         c.Check(err, check.Equals, os.ErrNotExist)
78         err = s.fs.Rename("/by_id/"+arvadostest.FooCollection+"/foo", "/by_id/"+arvadostest.FooCollection+"/bar")
79         c.Check(err, check.IsNil)
80
81         err = s.fs.Rename("/by_id", "/beep")
82         c.Check(err, check.Equals, ErrInvalidArgument)
83 }