12 type HashcheckSuiteSuite struct{}
14 // Gocheck boilerplate
15 var _ = Suite(&HashcheckSuiteSuite{})
17 func (h *HashcheckSuiteSuite) TestRead(c *C) {
18 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
22 hcr := HashCheckingReader{r, md5.New(), hash}
24 w.Write([]byte("foo"))
27 p, err := ioutil.ReadAll(hcr)
28 c.Check(len(p), Equals, 3)
29 c.Check(err, Equals, nil)
34 hcr := HashCheckingReader{r, md5.New(), hash}
36 w.Write([]byte("bar"))
39 p, err := ioutil.ReadAll(hcr)
40 c.Check(len(p), Equals, 3)
41 c.Check(err, Equals, BadChecksum)
45 func (h *HashcheckSuiteSuite) TestWriteTo(c *C) {
46 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
49 bb := bytes.NewBufferString("foo")
50 hcr := HashCheckingReader{bb, md5.New(), hash}
52 done := make(chan bool)
54 p, err := ioutil.ReadAll(r)
55 c.Check(len(p), Equals, 3)
56 c.Check(err, Equals, nil)
60 n, err := hcr.WriteTo(w)
62 c.Check(n, Equals, int64(3))
63 c.Check(err, Equals, nil)
68 bb := bytes.NewBufferString("bar")
69 hcr := HashCheckingReader{bb, md5.New(), hash}
71 done := make(chan bool)
73 p, err := ioutil.ReadAll(r)
74 c.Check(len(p), Equals, 3)
75 c.Check(err, Equals, nil)
79 n, err := hcr.WriteTo(w)
81 c.Check(n, Equals, int64(3))
82 c.Check(err, Equals, BadChecksum)