11 type UploadTestSuite struct{}
13 // Gocheck boilerplate
14 var _ = Suite(&UploadTestSuite{})
16 func (s *TestSuite) TestSimpleUpload(c *C) {
17 tmpdir, _ := ioutil.TempDir("", "")
22 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
24 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
25 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
27 c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
30 func (s *TestSuite) TestSimpleUploadTwofiles(c *C) {
31 tmpdir, _ := ioutil.TempDir("", "")
36 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
37 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
39 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
40 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
43 c.Check(str, Equals, ". 3858f62230ac3c915f300c664312c63f+6 0:3:file1.txt 3:3:file2.txt\n")
46 func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
47 tmpdir, _ := ioutil.TempDir("", "")
52 os.Mkdir(tmpdir+"/subdir", 0700)
54 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
55 ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
57 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
58 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
62 // streams can get added in either order because of scheduling
64 if str != `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
65 ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
66 ` && str != `./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
67 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
69 c.Error("Did not get expected manifest text")
73 func (s *TestSuite) TestSimpleUploadLarge(c *C) {
74 tmpdir, _ := ioutil.TempDir("", "")
79 file, _ := os.Create(tmpdir + "/" + "file1.txt")
80 data := make([]byte, 1024*1024-1)
82 data[i] = byte(i % 10)
84 for i := 0; i < 65; i++ {
89 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
91 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
92 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
95 c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
98 func (s *TestSuite) TestUploadEmptySubdir(c *C) {
99 tmpdir, _ := ioutil.TempDir("", "")
104 os.Mkdir(tmpdir+"/subdir", 0700)
106 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
108 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
109 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
112 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
116 func (s *TestSuite) TestUploadEmptyFile(c *C) {
117 tmpdir, _ := ioutil.TempDir("", "")
122 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600)
124 cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
125 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
128 c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
132 func (s *TestSuite) TestUploadError(c *C) {
133 tmpdir, _ := ioutil.TempDir("", "")
138 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
140 cw := CollectionWriter{&KeepErrorTestClient{}, nil, sync.Mutex{}}
141 str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
144 c.Check(str, Equals, "")