Exemple #1
0
func newStubResponseWriter(stub *testing.Stub) *stubResponseWriter {
	writer, buf := filetesting.NewStubWriter(stub)
	return &stubResponseWriter{
		Stub:   stub,
		Writer: writer,
		buf:    buf,

		ReturnHeader: make(http.Header),
	}
}
Exemple #2
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)
}
Exemple #3
0
func (*sizeSuite) TestSizingWriter(c *gc.C) {
	expected := "some data"
	stub := &testing.Stub{}
	writer, buffer := filetesting.NewStubWriter(stub)

	var st utils.SizeTracker
	sizingWriter := io.MultiWriter(writer, &st)
	n, err := sizingWriter.Write([]byte(expected))
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c, "Write")
	c.Check(n, gc.Equals, len(expected))
	c.Check(buffer.String(), gc.Equals, expected)
	c.Check(st.Size(), gc.Equals, int64(len(expected)))
}