1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 type UploadTestSuite struct{}
17 // Gocheck boilerplate
18 var _ = Suite(&UploadTestSuite{})
20 func (s *TestSuite) TestSimpleUpload(c *C) {
21 tmpdir, _ := ioutil.TempDir("", "")
26 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
28 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
29 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
31 c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
34 func (s *TestSuite) TestSimpleUploadTwofiles(c *C) {
35 tmpdir, _ := ioutil.TempDir("", "")
40 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
41 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
43 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
44 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
47 c.Check(str, Equals, ". 3858f62230ac3c915f300c664312c63f+6 0:3:file1.txt 3:3:file2.txt\n")
50 func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
51 tmpdir, _ := ioutil.TempDir("", "")
56 os.Mkdir(tmpdir+"/subdir", 0700)
58 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
59 ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
61 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
62 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
66 // streams can get added in either order because of scheduling
68 if str != `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
69 ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
70 ` && str != `./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
71 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
73 c.Error("Did not get expected manifest text")
77 func (s *TestSuite) TestSimpleUploadLarge(c *C) {
78 tmpdir, _ := ioutil.TempDir("", "")
83 file, _ := os.Create(tmpdir + "/" + "file1.txt")
84 data := make([]byte, 1024*1024-1)
86 data[i] = byte(i % 10)
88 for i := 0; i < 65; i++ {
93 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
95 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
96 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
99 c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
102 func (s *TestSuite) TestUploadEmptySubdir(c *C) {
103 tmpdir, _ := ioutil.TempDir("", "")
108 os.Mkdir(tmpdir+"/subdir", 0700)
110 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
112 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
113 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
116 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
120 func (s *TestSuite) TestUploadEmptyFile(c *C) {
121 tmpdir, _ := ioutil.TempDir("", "")
126 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600)
128 cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
129 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
132 c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
136 func (s *TestSuite) TestUploadError(c *C) {
137 tmpdir, _ := ioutil.TempDir("", "")
142 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
144 cw := CollectionWriter{0, &KeepErrorTestClient{}, nil, nil, sync.Mutex{}}
145 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
148 c.Check(str, Equals, "")