Beispiel #1
0
func (s *imagemanagerSuite) TestDeleteImage(c *gc.C) {
	var callCount int
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "ImageManager")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "DeleteImages")
		c.Check(arg, gc.DeepEquals, params.ImageFilterParams{
			Images: []params.ImageSpec{{
				Kind:   "lxc",
				Series: "trusty",
				Arch:   "amd64",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{
				Error: nil,
			}},
		}
		callCount++
		return nil
	})

	im := imagemanager.NewClient(apiCaller)
	err := im.DeleteImage("lxc", "trusty", "amd64")
	c.Check(err, jc.ErrorIsNil)
	c.Check(callCount, gc.Equals, 1)
}
Beispiel #2
0
// NewImagesManagerClient returns a imagemanager client for the root api endpoint
// that the environment command returns.
func (c *CachedImagesCommandBase) NewImagesManagerClient() (*imagemanager.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return imagemanager.NewClient(root), nil
}
Beispiel #3
0
func (s *imagemanagerSuite) TestDeleteImageCallError(c *gc.C) {
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return errors.New("an error")
	})

	im := imagemanager.NewClient(apiCaller)
	err := im.DeleteImage("lxc", "trusty", "amd64")
	c.Check(err, gc.ErrorMatches, "an error")
}
Beispiel #4
0
func (s *imagemanagerSuite) TestDeleteImageError(c *gc.C) {
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{
				Error: &params.Error{Message: "the devil made me do it", Code: "666"},
			}},
		}
		return nil
	})

	im := imagemanager.NewClient(apiCaller)
	err := im.DeleteImage("lxc", "trusty", "amd64")
	c.Check(err, gc.ErrorMatches, "the devil made me do it")
}
Beispiel #5
0
func (s *imagemanagerSuite) TestListImages(c *gc.C) {
	var callCount int
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "ImageManager")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "ListImages")
		c.Check(arg, gc.DeepEquals, params.ImageFilterParams{
			Images: []params.ImageSpec{{
				Kind:   "lxc",
				Series: "trusty",
				Arch:   "amd64",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.ListImageResult{})
		*(result.(*params.ListImageResult)) = params.ListImageResult{
			Result: []params.ImageMetadata{{
				Kind:    "lxc",
				Series:  "trusty",
				Arch:    "amd64",
				Created: dummyTime,
				URL:     "http://path",
			}},
		}
		callCount++
		return nil
	})

	im := imagemanager.NewClient(apiCaller)
	imageMetadata, err := im.ListImages("lxc", "trusty", "amd64")
	c.Check(err, jc.ErrorIsNil)
	c.Check(callCount, gc.Equals, 1)
	c.Check(imageMetadata, gc.HasLen, 1)
	metadata := imageMetadata[0]
	c.Assert(metadata, gc.Equals, params.ImageMetadata{
		Kind:    "lxc",
		Series:  "trusty",
		Arch:    "amd64",
		Created: dummyTime,
		URL:     "http://path",
	})
}