X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/97e4c0fa88224bb282ddd502dc8fda18cca3ba21..6247858b8041caf4899da501456661d25dd5491b:/services/crunch-run/upload_test.go diff --git a/services/crunch-run/upload_test.go b/services/crunch-run/upload_test.go index b4b1efd107..86dab41a64 100644 --- a/services/crunch-run/upload_test.go +++ b/services/crunch-run/upload_test.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( @@ -5,7 +9,9 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "sync" + "syscall" ) type UploadTestSuite struct{} @@ -13,6 +19,25 @@ 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() { @@ -21,26 +46,32 @@ func (s *TestSuite) TestSimpleUpload(c *C) { 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) { @@ -54,8 +85,8 @@ 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) @@ -88,8 +119,8 @@ func (s *TestSuite) TestSimpleUploadLarge(c *C) { 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") @@ -105,8 +136,8 @@ func (s *TestSuite) TestUploadEmptySubdir(c *C) { 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 @@ -121,8 +152,8 @@ func (s *TestSuite) TestUploadEmptyFile(c *C) { 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 @@ -137,8 +168,8 @@ func (s *TestSuite) TestUploadError(c *C) { 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, "")