1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
18 type UploadTestSuite struct{}
20 // Gocheck boilerplate
21 var _ = Suite(&UploadTestSuite{})
23 type KeepTestClient struct {
26 func (k KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
27 return fmt.Sprintf("%x+%v", md5.Sum(buf), len(buf)), len(buf), nil
30 func (s *TestSuite) TestSimpleUpload(c *C) {
31 tmpdir, _ := ioutil.TempDir("", "")
36 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
38 str, err := WriteTree(KeepTestClient{}, tmpdir)
40 c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
43 func (s *TestSuite) TestSimpleUploadThreeFiles(c *C) {
44 tmpdir, _ := ioutil.TempDir("", "")
49 for _, err := range []error{
50 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600),
51 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600),
52 os.Symlink("./file2.txt", tmpdir+"/file3.txt"),
53 syscall.Mkfifo(tmpdir+"/ignore.fifo", 0600),
58 str, err := WriteTree(KeepTestClient{}, tmpdir)
60 c.Check(str, Equals, ". aa65a413921163458c52fea478d5d3ee+9 0:3:file1.txt 3:3:file2.txt 6:3:file3.txt\n")
63 func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
64 tmpdir, _ := ioutil.TempDir("", "")
69 os.Mkdir(tmpdir+"/subdir", 0700)
71 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
72 ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
74 str, err := WriteTree(KeepTestClient{}, tmpdir)
76 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
77 ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
81 func (s *TestSuite) TestSimpleUploadLarge(c *C) {
82 tmpdir, _ := ioutil.TempDir("", "")
87 file, _ := os.Create(tmpdir + "/" + "file1.txt")
88 data := make([]byte, 1024*1024-1)
90 data[i] = byte(i % 10)
92 for i := 0; i < 65; i++ {
97 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
99 str, err := WriteTree(KeepTestClient{}, tmpdir)
101 c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
104 func (s *TestSuite) TestUploadEmptySubdir(c *C) {
105 tmpdir, _ := ioutil.TempDir("", "")
110 os.Mkdir(tmpdir+"/subdir", 0700)
112 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
114 str, err := WriteTree(KeepTestClient{}, tmpdir)
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 str, err := WriteTree(KeepTestClient{}, tmpdir)
130 c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
134 type KeepErrorTestClient struct {
137 func (k KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
138 return "", 0, errors.New("Failed!")
141 func (s *TestSuite) TestUploadError(c *C) {
142 tmpdir, _ := ioutil.TempDir("", "")
147 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
149 str, err := WriteTree(KeepErrorTestClient{}, tmpdir)
151 c.Check(str, Equals, "")