13219: Checks for expired run time and cancel container if needed.
[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(err, check.IsNil)
46         c.Check(len(fis), check.Equals, 0)
47 }
48
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)
55
56         err = s.fs.Mkdir("/by_id/"+arvadostest.FooCollection, 0755)
57         c.Check(err, check.Equals, os.ErrExist)
58
59         f, err = s.fs.Open("/by_id/" + arvadostest.NonexistentCollection)
60         c.Assert(err, check.Equals, os.ErrNotExist)
61
62         for _, path := range []string{
63                 arvadostest.FooCollection,
64                 arvadostest.FooPdh,
65                 arvadostest.AProjectUUID + "/" + arvadostest.FooCollectionName,
66         } {
67                 f, err = s.fs.Open("/by_id/" + path)
68                 c.Assert(err, check.IsNil)
69                 fis, err = f.Readdir(-1)
70                 var names []string
71                 for _, fi := range fis {
72                         names = append(names, fi.Name())
73                 }
74                 c.Check(names, check.DeepEquals, []string{"foo"})
75         }
76
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)
80         var names []string
81         for _, fi := range fis {
82                 names = append(names, fi.Name())
83         }
84         c.Check(names, check.DeepEquals, []string{"baz"})
85
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)
96
97         err = s.fs.Rename("/by_id", "/beep")
98         c.Check(err, check.Equals, ErrInvalidArgument)
99 }