func useTestImageData(files map[string]string) { if files != nil { sstesting.TestRoundTripper.Sub = &CountingRoundTripper{ CannedRoundTripper: coretesting.NewCannedRoundTripper(files, nil), } } else { sstesting.TestRoundTripper.Sub = nil } }
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") }
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") }
func SetRoundTripperFiles(files map[string]string, errorFiles map[string]int) { TestRoundTripper.Sub = testing.NewCannedRoundTripper(files, errorFiles) }
func (s *TestDataSuite) SetUpSuite(c *gc.C) { TestRoundTripper.Sub = testing.NewCannedRoundTripper(imageData, map[string]int{"test://unauth": http.StatusUnauthorized}) }
func (s *simplestreamsSuite) SetUpSuite(c *gc.C) { s.LocalLiveSimplestreamsSuite.SetUpSuite(c) sstesting.TestRoundTripper.Sub = coretesting.NewCannedRoundTripper( guiData, map[string]int{"test://unauth": http.StatusUnauthorized}) }