1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
18 type UploadTestSuite struct{}
20 // Gocheck boilerplate
21 var _ = Suite(&UploadTestSuite{})
23 func writeTree(cw *CollectionWriter, root string, status *log.Logger) (mt string, err error) {
24 walkUpload := cw.BeginUpload(root, status)
26 err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
27 info, _ = os.Stat(path)
28 if info.Mode().IsRegular() {
29 return walkUpload.UploadFile(path, path)
34 cw.EndUpload(walkUpload)
38 mt, err = cw.ManifestText()
42 func (s *TestSuite) TestSimpleUpload(c *C) {
43 tmpdir, _ := ioutil.TempDir("", "")
48 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
50 kc := &KeepTestClient{}
52 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
53 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
55 c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
58 func (s *TestSuite) TestUploadThreeFiles(c *C) {
59 tmpdir, _ := ioutil.TempDir("", "")
64 for _, err := range []error{
65 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600),
66 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600),
67 os.Symlink("./file2.txt", tmpdir+"/file3.txt"),
68 syscall.Mkfifo(tmpdir+"/ignore.fifo", 0600),
73 kc := &KeepTestClient{}
75 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
76 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
79 c.Check(str, Equals, ". aa65a413921163458c52fea478d5d3ee+9 0:3:file1.txt 3:3:file2.txt 6:3:file3.txt\n")
82 func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
83 tmpdir, _ := ioutil.TempDir("", "")
88 os.Mkdir(tmpdir+"/subdir", 0700)
90 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
91 ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
93 kc := &KeepTestClient{}
95 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
96 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
100 // streams can get added in either order because of scheduling
102 if str != `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
103 ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
104 ` && str != `./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
105 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
107 c.Error("Did not get expected manifest text")
111 func (s *TestSuite) TestSimpleUploadLarge(c *C) {
112 tmpdir, _ := ioutil.TempDir("", "")
117 file, _ := os.Create(tmpdir + "/" + "file1.txt")
118 data := make([]byte, 1024*1024-1)
119 for i := range data {
120 data[i] = byte(i % 10)
122 for i := 0; i < 65; i++ {
127 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
129 kc := &KeepTestClient{}
131 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
132 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
135 c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
138 func (s *TestSuite) TestUploadEmptySubdir(c *C) {
139 tmpdir, _ := ioutil.TempDir("", "")
144 os.Mkdir(tmpdir+"/subdir", 0700)
146 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
148 kc := &KeepTestClient{}
150 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
151 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
154 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
158 func (s *TestSuite) TestUploadEmptyFile(c *C) {
159 tmpdir, _ := ioutil.TempDir("", "")
164 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600)
166 kc := &KeepTestClient{}
168 cw := CollectionWriter{0, kc, nil, nil, sync.Mutex{}}
169 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
172 c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
176 func (s *TestSuite) TestUploadError(c *C) {
177 tmpdir, _ := ioutil.TempDir("", "")
182 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
184 cw := CollectionWriter{0, &KeepErrorTestClient{}, nil, nil, sync.Mutex{}}
185 str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
188 c.Check(str, Equals, "")