func newStubReadCloser(stub *testing.Stub, content string) io.ReadCloser { return &stubReadCloser{ Reader: filetesting.NewStubReader(stub, content), Closer: &filetesting.StubCloser{ Stub: stub, }, } }
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) }
func (*sizeSuite) TestSizingReaderOkay(c *gc.C) { expected := "some data" stub := &testing.Stub{} reader := filetesting.NewStubReader(stub, expected) var st utils.SizeTracker sizingReader := io.TeeReader(reader, &st) data, err := ioutil.ReadAll(sizingReader) c.Assert(err, jc.ErrorIsNil) stub.CheckCallNames(c, "Read", "Read") c.Check(string(data), gc.Equals, expected) c.Check(st.Size(), gc.Equals, int64(len(expected))) }