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.*`,
104 // Strangely, webdav deletes dst if you do
105 // "move nonexistent dst" -- otherwise we
106 // would repeat the above "move testfile
109 cmd: "move testfile nonexistentdir\n",
110 match: `(?ms).*Moving .* failed.*`,
115 match: `(?ms).*newdir0.* 0 .*`,
119 cmd: "move newdir0/testfile emptyfile/bogus/\n",
120 match: `(?ms).*Moving .* failed.*`,
124 cmd: "mkcol newdir1\n",
125 match: `(?ms).*Creating .* succeeded.*`,
129 cmd: "move newdir0/testfile newdir1\n",
130 match: `(?ms).*Moving .* succeeded.*`,
134 cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n",
135 match: `(?ms).*Uploading .* succeeded.*`,
139 cmd: "mkcol newdir2\n",
140 match: `(?ms).*Creating .* succeeded.*`,
144 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
145 match: `(?ms).*Uploading .* succeeded.*`,
149 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
150 match: `(?ms).*succeeded.*`,
155 cmd: "rmcol newdir2\n",
156 match: `(?ms).*Deleting collection .* succeeded.*`,
160 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
161 match: `(?ms).*Downloading .* failed.*`,
164 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
166 os.Remove(checkfile.Name())
168 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
169 cmd.Stdin = bytes.NewBufferString(trial.cmd)
170 stdout, err := cmd.StdoutPipe()
171 c.Assert(err, check.Equals, nil)
172 cmd.Stderr = cmd.Stdout
176 _, err = io.Copy(&buf, stdout)
177 c.Check(err, check.Equals, nil)
179 c.Check(err, check.Equals, nil)
180 c.Check(buf.String(), check.Matches, trial.match)
182 if trial.data == nil {
185 checkfile, err = os.Open(checkfile.Name())
186 c.Assert(err, check.IsNil)
187 checkfile.Seek(0, os.SEEK_SET)
188 got, err := ioutil.ReadAll(checkfile)
189 c.Check(got, check.DeepEquals, trial.data)
190 c.Check(err, check.IsNil)