13111: Mount collections on demand in mnt/by_id/.
[arvados.git] / sdk / go / arvados / site_fs_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
10         "git.curoverse.com/arvados.git/sdk/go/arvadostest"
11         check "gopkg.in/check.v1"
12 )
13
14 var _ = check.Suite(&SiteFSSuite{})
15
16 type SiteFSSuite struct {
17         client *Client
18         fs     FileSystem
19         kc     keepClient
20 }
21
22 func (s *SiteFSSuite) SetUpTest(c *check.C) {
23         s.client = NewClientFromEnv()
24         s.kc = &keepClientStub{
25                 blocks: map[string][]byte{
26                         "3858f62230ac3c915f300c664312c63f": []byte("foobar"),
27                 }}
28         s.fs = s.client.SiteFileSystem(s.kc)
29 }
30
31 func (s *SiteFSSuite) TestHttpFileSystemInterface(c *check.C) {
32         _, ok := s.fs.(http.FileSystem)
33         c.Check(ok, check.Equals, true)
34 }
35
36 func (s *SiteFSSuite) TestByIDEmpty(c *check.C) {
37         f, err := s.fs.Open("/by_id")
38         c.Assert(err, check.IsNil)
39         fis, err := f.Readdir(-1)
40         c.Check(len(fis), check.Equals, 0)
41 }
42
43 func (s *SiteFSSuite) TestByUUID(c *check.C) {
44         f, err := s.fs.Open("/by_id")
45         c.Assert(err, check.IsNil)
46         fis, err := f.Readdir(-1)
47         c.Check(err, check.IsNil)
48         c.Check(len(fis), check.Equals, 0)
49
50         f, err = s.fs.Open("/by_id/" + arvadostest.FooCollection)
51         c.Assert(err, check.IsNil)
52         fis, err = f.Readdir(-1)
53         var names []string
54         for _, fi := range fis {
55                 names = append(names, fi.Name())
56         }
57         c.Check(names, check.DeepEquals, []string{"foo"})
58 }