15370: Fix flaky test.
[arvados.git] / sdk / go / keepclient / hashcheck_test.go
index db748ee98ed2b247d37f21b931b03283f5e70bb1..44345afda61c5535ee1bfa1232c3369827f00be5 100644 (file)
@@ -8,9 +8,10 @@ import (
        "bytes"
        "crypto/md5"
        "fmt"
-       . "gopkg.in/check.v1"
        "io"
        "io/ioutil"
+
+       . "gopkg.in/check.v1"
 )
 
 type HashcheckSuiteSuite struct{}
@@ -86,4 +87,17 @@ func (h *HashcheckSuiteSuite) TestWriteTo(c *C) {
                c.Check(err, Equals, BadChecksum)
                <-done
        }
+
+       // If WriteTo stops early due to a write error, return the
+       // write error (not "bad checksum").
+       {
+               input := bytes.NewBuffer(make([]byte, 1<<26))
+               hcr := HashCheckingReader{input, md5.New(), hash}
+               r, w := io.Pipe()
+               r.Close()
+               n, err := hcr.WriteTo(w)
+               c.Check(n, Equals, int64(0))
+               c.Check(err, NotNil)
+               c.Check(err, Not(Equals), BadChecksum)
+       }
 }