12 type UploadTestSuite struct{}
14 // Gocheck boilerplate
15 var _ = Suite(&UploadTestSuite{})
17 type KeepTestClient struct {
20 func (k KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
21 return fmt.Sprintf("%x+%v", md5.Sum(buf), len(buf)), len(buf), nil
24 func (s *TestSuite) TestSimpleUpload(c *C) {
25 tmpdir, _ := ioutil.TempDir("", "")
30 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
32 str, err := WriteTree(KeepTestClient{}, tmpdir)
34 c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
37 func (s *TestSuite) TestSimpleUploadTwofiles(c *C) {
38 tmpdir, _ := ioutil.TempDir("", "")
43 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
44 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
46 str, err := WriteTree(KeepTestClient{}, tmpdir)
48 c.Check(str, Equals, ". 3858f62230ac3c915f300c664312c63f+6 0:3:file1.txt 3:3:file2.txt\n")
51 func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
52 tmpdir, _ := ioutil.TempDir("", "")
57 os.Mkdir(tmpdir+"/subdir", 0700)
59 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
60 ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
62 str, err := WriteTree(KeepTestClient{}, tmpdir)
64 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
65 ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt
69 func (s *TestSuite) TestSimpleUploadLarge(c *C) {
70 tmpdir, _ := ioutil.TempDir("", "")
75 file, _ := os.Create(tmpdir + "/" + "file1.txt")
76 data := make([]byte, 1024*1024-1)
78 data[i] = byte(i % 10)
80 for i := 0; i < 65; i++ {
85 ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
87 str, err := WriteTree(KeepTestClient{}, tmpdir)
89 c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
92 func (s *TestSuite) TestUploadEmptySubdir(c *C) {
93 tmpdir, _ := ioutil.TempDir("", "")
98 os.Mkdir(tmpdir+"/subdir", 0700)
100 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
102 str, err := WriteTree(KeepTestClient{}, tmpdir)
104 c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
108 func (s *TestSuite) TestUploadEmptyFile(c *C) {
109 tmpdir, _ := ioutil.TempDir("", "")
114 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600)
116 str, err := WriteTree(KeepTestClient{}, tmpdir)
118 c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
122 type KeepErrorTestClient struct {
125 func (k KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
126 return "", 0, errors.New("Failed!")
129 func (s *TestSuite) TestUploadError(c *C) {
130 tmpdir, _ := ioutil.TempDir("", "")
135 ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
137 str, err := WriteTree(KeepErrorTestClient{}, tmpdir)
139 c.Check(str, Equals, "")