1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
16 type HashcheckSuiteSuite struct{}
18 // Gocheck boilerplate
19 var _ = Suite(&HashcheckSuiteSuite{})
21 func (h *HashcheckSuiteSuite) TestRead(c *C) {
22 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
26 hcr := HashCheckingReader{r, md5.New(), hash}
28 w.Write([]byte("foo"))
31 p, err := ioutil.ReadAll(hcr)
32 c.Check(len(p), Equals, 3)
33 c.Check(err, Equals, nil)
38 hcr := HashCheckingReader{r, md5.New(), hash}
40 w.Write([]byte("bar"))
43 p, err := ioutil.ReadAll(hcr)
44 c.Check(len(p), Equals, 3)
45 c.Check(err, Equals, BadChecksum)
49 func (h *HashcheckSuiteSuite) TestWriteTo(c *C) {
50 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
53 bb := bytes.NewBufferString("foo")
54 hcr := HashCheckingReader{bb, md5.New(), hash}
56 done := make(chan bool)
58 p, err := ioutil.ReadAll(r)
59 c.Check(len(p), Equals, 3)
60 c.Check(err, Equals, nil)
64 n, err := hcr.WriteTo(w)
66 c.Check(n, Equals, int64(3))
67 c.Check(err, Equals, nil)
72 bb := bytes.NewBufferString("bar")
73 hcr := HashCheckingReader{bb, md5.New(), hash}
75 done := make(chan bool)
77 p, err := ioutil.ReadAll(r)
78 c.Check(len(p), Equals, 3)
79 c.Check(err, Equals, nil)
83 n, err := hcr.WriteTo(w)
85 c.Check(n, Equals, int64(3))
86 c.Check(err, Equals, BadChecksum)