+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
package main
import (
"io/ioutil"
"log"
"os"
+ "path/filepath"
"sync"
+ "syscall"
)
type UploadTestSuite struct{}
// Gocheck boilerplate
var _ = Suite(&UploadTestSuite{})
+func writeTree(cw *CollectionWriter, root string, status *log.Logger) (mt string, err error) {
+ walkUpload := cw.BeginUpload(root, status)
+
+ err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+ info, _ = os.Stat(path)
+ if info.Mode().IsRegular() {
+ return walkUpload.UploadFile(path, path)
+ }
+ return nil
+ })
+
+ cw.EndUpload(walkUpload)
+ if err != nil {
+ return "", err
+ }
+ mt, err = cw.ManifestText()
+ return
+}
+
func (s *TestSuite) TestSimpleUpload(c *C) {
tmpdir, _ := ioutil.TempDir("", "")
defer func() {
ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
c.Check(str, Equals, ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt\n")
}
-func (s *TestSuite) TestSimpleUploadTwofiles(c *C) {
+func (s *TestSuite) TestUploadThreeFiles(c *C) {
tmpdir, _ := ioutil.TempDir("", "")
defer func() {
os.RemoveAll(tmpdir)
}()
- ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
- ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
+ for _, err := range []error{
+ ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600),
+ ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600),
+ os.Symlink("./file2.txt", tmpdir+"/file3.txt"),
+ syscall.Mkfifo(tmpdir+"/ignore.fifo", 0600),
+ } {
+ c.Assert(err, IsNil)
+ }
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
- c.Check(str, Equals, ". 3858f62230ac3c915f300c664312c63f+6 0:3:file1.txt 3:3:file2.txt\n")
+ c.Check(str, Equals, ". aa65a413921163458c52fea478d5d3ee+9 0:3:file1.txt 3:3:file2.txt 6:3:file3.txt\n")
}
func (s *TestSuite) TestSimpleUploadSubdir(c *C) {
ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
ioutil.WriteFile(tmpdir+"/subdir/file2.txt", []byte("bar"), 0600)
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600)
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
c.Check(str, Equals, ". 00ecf01e0d93385115c9f8bed757425d+67108864 485cd630387b6b1846fe429f261ea05f+1048514 0:68157375:file1.txt 68157375:3:file2.txt\n")
ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt
ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600)
- cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, IsNil)
c.Check(str, Equals, `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1.txt
ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
- cw := CollectionWriter{&KeepErrorTestClient{}, nil, sync.Mutex{}}
- str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0))
+ cw := CollectionWriter{0, &KeepErrorTestClient{}, nil, nil, sync.Mutex{}}
+ str, err := writeTree(&cw, tmpdir, log.New(os.Stdout, "", 0))
c.Check(err, NotNil)
c.Check(str, Equals, "")