Esempio 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
	}
}
Esempio 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")
}
Esempio 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")
}
Esempio n. 4
0
File: testing.go Progetto: bac/juju
func SetRoundTripperFiles(files map[string]string, errorFiles map[string]int) {
	TestRoundTripper.Sub = testing.NewCannedRoundTripper(files, errorFiles)
}
Esempio n. 5
0
File: testing.go Progetto: bac/juju
func (s *TestDataSuite) SetUpSuite(c *gc.C) {
	TestRoundTripper.Sub = testing.NewCannedRoundTripper(imageData, map[string]int{"test://unauth": http.StatusUnauthorized})
}
Esempio 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})
}