Example #1
0
func (s *FingerprintSuite) TestGenerateFingerprintOkay(c *gc.C) {
	expected, _ := newFingerprint(c, "spamspamspam")
	s.hash.ReturnSum = expected
	s.hash.Writer, _ = filetesting.NewStubWriter(s.stub)
	reader := filetesting.NewStubReader(s.stub, "spamspamspam")

	fp, err := hash.GenerateFingerprint(reader, s.newHash)
	c.Assert(err, jc.ErrorIsNil)
	sum := fp.Bytes()

	s.stub.CheckCallNames(c, "newHash", "Read", "Write", "Read", "Sum")
	c.Check(sum, jc.DeepEquals, expected)
}
Example #2
0
func (s *HashSuite) TestHashingWriter(c *gc.C) {
	data := "some data"
	newHash, _ := hash.SHA384()
	expected, err := hash.GenerateFingerprint(strings.NewReader(data), newHash)
	c.Assert(err, jc.ErrorIsNil)
	var writer bytes.Buffer

	h := newHash()
	hashingWriter := io.MultiWriter(&writer, h)
	_, err = hashingWriter.Write([]byte(data))
	c.Assert(err, jc.ErrorIsNil)
	fp := hash.NewValidFingerprint(h)

	c.Check(fp, jc.DeepEquals, expected)
	c.Check(writer.String(), gc.Equals, data)
}
Example #3
0
func (s *FingerprintSuite) TestGenerateFingerprintNil(c *gc.C) {
	_, err := hash.GenerateFingerprint(nil, s.newHash)

	s.stub.CheckNoCalls(c)
	c.Check(err, gc.ErrorMatches, `missing reader`)
}