1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/arvados"
16 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
17 check "gopkg.in/check.v1"
20 func (s *IntegrationSuite) TestWebdavWithCadaver(c *check.C) {
21 testdata := []byte("the human tragedy consists in the necessity of living with the consequences of actions performed under the pressure of compulsions we do not understand")
23 localfile, err := ioutil.TempFile("", "localfile")
24 c.Assert(err, check.IsNil)
25 defer os.Remove(localfile.Name())
26 localfile.Write(testdata)
28 emptyfile, err := ioutil.TempFile("", "emptyfile")
29 c.Assert(err, check.IsNil)
30 defer os.Remove(emptyfile.Name())
32 checkfile, err := ioutil.TempFile("", "checkfile")
33 c.Assert(err, check.IsNil)
34 defer os.Remove(checkfile.Name())
36 var newCollection arvados.Collection
37 arv := arvados.NewClientFromEnv()
38 arv.AuthToken = arvadostest.ActiveToken
39 err = arv.RequestAndDecode(&newCollection, "POST", "/arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil)
40 c.Assert(err, check.IsNil)
41 writePath := "/c=" + newCollection.UUID + "/t=" + arv.AuthToken + "/"
43 readPath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/"
44 type testcase struct {
50 for _, trial := range []testcase{
54 match: `(?ms).*dir1 *0 .*`,
59 match: `(?ms).*bar *3.*foo *3 .*`,
62 path: readPath + "_/dir1",
64 match: `(?ms).*bar *3.*foo *3 .*`,
67 path: readPath + "dir1/",
69 match: `(?ms).*bar *3.*foo *3 .*`,
73 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
74 match: `(?ms).*Not Found.*`,
78 cmd: "put '" + emptyfile.Name() + "' emptyfile\n",
79 match: `(?ms).*Uploading .* succeeded.*`,
83 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
84 match: `(?ms).*Downloading .* succeeded.*`,
89 cmd: "put '" + localfile.Name() + "' testfile\n",
90 match: `(?ms).*Uploading .* succeeded.*`,
94 cmd: "get testfile '" + checkfile.Name() + "'\n",
95 match: `(?ms).*succeeded.*`,
100 cmd: "move testfile newdir0\n",
101 match: `(?ms).*Moving .* succeeded.*`,
105 cmd: "move testfile newdir0\n",
106 match: `(?ms).*Moving .* failed.*`,
111 match: `(?ms).*newdir0.* 0 .*`,
115 cmd: "move newdir0/testfile emptyfile/bogus/\n",
116 match: `(?ms).*Moving .* failed.*`,
120 cmd: "mkcol newdir1\n",
121 match: `(?ms).*Creating .* succeeded.*`,
125 cmd: "move newdir0/testfile newdir1\n",
126 match: `(?ms).*Moving .* succeeded.*`,
130 cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n",
131 match: `(?ms).*Uploading .* succeeded.*`,
135 cmd: "mkcol newdir2\n",
136 match: `(?ms).*Creating .* succeeded.*`,
140 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
141 match: `(?ms).*Uploading .* succeeded.*`,
145 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
146 match: `(?ms).*succeeded.*`,
151 cmd: "rmcol newdir2\n",
152 match: `(?ms).*Deleting collection .* succeeded.*`,
156 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
157 match: `(?ms).*Downloading .* failed.*`,
160 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
162 os.Remove(checkfile.Name())
164 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
165 cmd.Stdin = bytes.NewBufferString(trial.cmd)
166 stdout, err := cmd.StdoutPipe()
167 c.Assert(err, check.Equals, nil)
168 cmd.Stderr = cmd.Stdout
172 _, err = io.Copy(&buf, stdout)
173 c.Check(err, check.Equals, nil)
175 c.Check(err, check.Equals, nil)
176 c.Check(buf.String(), check.Matches, trial.match)
178 if trial.data == nil {
181 checkfile, err = os.Open(checkfile.Name())
182 c.Assert(err, check.IsNil)
183 checkfile.Seek(0, os.SEEK_SET)
184 got, err := ioutil.ReadAll(checkfile)
185 c.Check(got, check.DeepEquals, trial.data)
186 c.Check(err, check.IsNil)