Merge branch '11807-yaml-to-json'
[arvados.git] / services / crunch-run / upload_test.go
index d66d9de36398ba90d0b670d33d4b7621b859da06..86ad1b32ae074b3acfd577e164c174dd099099cd 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -21,7 +25,7 @@ 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")
@@ -36,7 +40,7 @@ func (s *TestSuite) TestSimpleUploadTwofiles(c *C) {
        ioutil.WriteFile(tmpdir+"/"+"file1.txt", []byte("foo"), 0600)
        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)
@@ -54,13 +58,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 +92,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 +109,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 +125,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 +141,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)