X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/070fdce365074a76d4da2e118574fd1d4f3515c5..15b5b59f5902fdc0fe4eb5366ba3b654b117d7df:/services/crunch-run/upload_test.go?ds=inline diff --git a/services/crunch-run/upload_test.go b/services/crunch-run/upload_test.go index d66d9de363..96ea2b1190 100644 --- a/services/crunch-run/upload_test.go +++ b/services/crunch-run/upload_test.go @@ -1,11 +1,17 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( - . "gopkg.in/check.v1" "io/ioutil" "log" "os" "sync" + "syscall" + + . "gopkg.in/check.v1" ) type UploadTestSuite struct{} @@ -21,26 +27,32 @@ func (s *TestSuite) TestSimpleUpload(c *C) { ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600) - cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(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) TestSimpleUploadThreefiles(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{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(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,13 +66,20 @@ 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{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0)) c.Check(err, IsNil) - c.Check(str, Equals, `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt + + // streams can get added in either order because of scheduling + // of goroutines. + if str != `. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt ./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt -`) +` && str != `./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:file2.txt +. acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:file1.txt +` { + c.Error("Did not get expected manifest text") + } } func (s *TestSuite) TestSimpleUploadLarge(c *C) { @@ -81,7 +100,7 @@ func (s *TestSuite) TestSimpleUploadLarge(c *C) { ioutil.WriteFile(tmpdir+"/"+"file2.txt", []byte("bar"), 0600) - cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0)) c.Check(err, IsNil) @@ -98,7 +117,7 @@ func (s *TestSuite) TestUploadEmptySubdir(c *C) { ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600) - cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0)) c.Check(err, IsNil) @@ -114,7 +133,7 @@ func (s *TestSuite) TestUploadEmptyFile(c *C) { ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte(""), 0600) - cw := CollectionWriter{&KeepTestClient{}, nil, sync.Mutex{}} + cw := CollectionWriter{0, &KeepTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0)) c.Check(err, IsNil) @@ -130,7 +149,7 @@ func (s *TestSuite) TestUploadError(c *C) { ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600) - cw := CollectionWriter{&KeepErrorTestClient{}, nil, sync.Mutex{}} + cw := CollectionWriter{0, &KeepErrorTestClient{}, nil, nil, sync.Mutex{}} str, err := cw.WriteTree(tmpdir, log.New(os.Stdout, "", 0)) c.Check(err, NotNil)