Exemplo n.º 1
0
func useTestImageData(files map[string]string) {
	if files != nil {
		sstesting.TestRoundTripper.Sub = &CountingRoundTripper{
			CannedRoundTripper: coretesting.NewCannedRoundTripper(files, nil),
		}
	} else {
		sstesting.TestRoundTripper.Sub = nil
	}
}
Exemplo n.º 2
0
func (s *metadataSuite) TestCannedRoundTripperMissing(c *gc.C) {
	vrt := testing.NewCannedRoundTripper(map[string]string{"a": "a-content"}, nil)
	c.Assert(vrt, gc.NotNil)
	req := &http.Request{URL: &url.URL{Path: "no-such-file"}}
	resp, err := vrt.RoundTrip(req)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(resp, gc.NotNil)
	content, err := ioutil.ReadAll(resp.Body)
	c.Assert(string(content), gc.Equals, "")
	c.Assert(resp.ContentLength, gc.Equals, int64(0))
	c.Assert(resp.StatusCode, gc.Equals, http.StatusNotFound)
	c.Assert(resp.Status, gc.Equals, "404 Not Found")
}
Exemplo n.º 3
0
func (s *metadataSuite) TestCannedRoundTripper(c *gc.C) {
	aContent := "a-content"
	vrt := testing.NewCannedRoundTripper(map[string]string{
		"a": aContent,
		"b": "b-content",
	}, nil)
	c.Assert(vrt, gc.NotNil)
	req := &http.Request{URL: &url.URL{Path: "a"}}
	resp, err := vrt.RoundTrip(req)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(resp, gc.NotNil)
	content, err := ioutil.ReadAll(resp.Body)
	c.Assert(string(content), gc.Equals, aContent)
	c.Assert(resp.ContentLength, gc.Equals, int64(len(aContent)))
	c.Assert(resp.StatusCode, gc.Equals, http.StatusOK)
	c.Assert(resp.Status, gc.Equals, "200 OK")
}
Exemplo n.º 4
0
Arquivo: testing.go Projeto: bac/juju
func SetRoundTripperFiles(files map[string]string, errorFiles map[string]int) {
	TestRoundTripper.Sub = testing.NewCannedRoundTripper(files, errorFiles)
}
Exemplo n.º 5
0
Arquivo: testing.go Projeto: bac/juju
func (s *TestDataSuite) SetUpSuite(c *gc.C) {
	TestRoundTripper.Sub = testing.NewCannedRoundTripper(imageData, map[string]int{"test://unauth": http.StatusUnauthorized})
}
Exemplo n.º 6
0
func (s *simplestreamsSuite) SetUpSuite(c *gc.C) {
	s.LocalLiveSimplestreamsSuite.SetUpSuite(c)
	sstesting.TestRoundTripper.Sub = coretesting.NewCannedRoundTripper(
		guiData, map[string]int{"test://unauth": http.StatusUnauthorized})
}