Пример #1
0
func (s *FingerprintSuite) TestParseHexFingerprint(c *gc.C) {
	expected, hexSum := newFingerprint(c, "spamspamspam")

	fp, err := hash.ParseHexFingerprint(hexSum, s.validate)
	c.Assert(err, jc.ErrorIsNil)
	sum := fp.Bytes()

	s.stub.CheckCallNames(c, "validate")
	c.Check(sum, jc.DeepEquals, expected)
}
Пример #2
0
func (s *HashSuite) TestHashingReader(c *gc.C) {
	expected := "some data"
	stub := &testing.Stub{}
	reader := &filetesting.StubReader{
		Stub: stub,
		ReturnRead: &fakeStream{
			data: expected,
		},
	}

	newHash, validate := hash.SHA384()
	h := newHash()
	hashingReader := io.TeeReader(reader, h)
	data, err := ioutil.ReadAll(hashingReader)
	c.Assert(err, jc.ErrorIsNil)
	fp := hash.NewValidFingerprint(h)
	hexSum := fp.Hex()
	fpAgain, err := hash.ParseHexFingerprint(hexSum, validate)
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c, "Read") // The EOF was mixed with the data.
	c.Check(string(data), gc.Equals, expected)
	c.Check(fpAgain, jc.DeepEquals, fp)
}