コード例 #1
0
ファイル: client_test.go プロジェクト: imoapps/juju
func (s *imagemetadataSuite) TestDeleteFailure(c *gc.C) {
	called := false
	msg := "save failure"

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Delete")

			results := result.(*params.ErrorResults)
			results.Results = []params.ErrorResult{
				{&params.Error{Message: msg}},
			}
			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	err := client.Delete("tst12345")
	c.Assert(err, gc.ErrorMatches, msg)
	c.Assert(called, jc.IsTrue)
}
コード例 #2
0
ファイル: cloudimagemetadata.go プロジェクト: imoapps/juju
// NewImageMetadataAPI returns a image metadata api for the root api endpoint
// that the environment command returns.
func (c *cloudImageMetadataCommandBase) NewImageMetadataAPI() (*imagemetadata.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return imagemetadata.NewClient(root), nil
}
コード例 #3
0
ファイル: client_test.go プロジェクト: imoapps/juju
func (s *imagemetadataSuite) TestDeleteMultipleResult(c *gc.C) {
	imageId := "tst12345"
	called := false

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Delete")

			results := result.(*params.ErrorResults)
			results.Results = []params.ErrorResult{{}, {}}
			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	err := client.Delete(imageId)
	c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta(`expected to find one result for image id "tst12345" but found 2`))
	c.Assert(called, jc.IsTrue)
}
コード例 #4
0
ファイル: client_test.go プロジェクト: imoapps/juju
func (s *imagemetadataSuite) TestDelete(c *gc.C) {
	imageId := "tst12345"
	called := false

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Delete")

			c.Assert(a, gc.FitsTypeOf, params.MetadataImageIds{})
			c.Assert(a.(params.MetadataImageIds).Ids, gc.DeepEquals, []string{imageId})

			results := result.(*params.ErrorResults)
			results.Results = []params.ErrorResult{{}}
			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	err := client.Delete(imageId)
	c.Check(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
}
コード例 #5
0
ファイル: client_test.go プロジェクト: imoapps/juju
func (s *imagemetadataSuite) TestSave(c *gc.C) {
	m := params.CloudImageMetadata{}
	called := false

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Save")

			c.Assert(a, gc.FitsTypeOf, params.MetadataSaveParams{})
			args := a.(params.MetadataSaveParams)
			c.Assert(args.Metadata, gc.HasLen, 1)
			c.Assert(args.Metadata, jc.DeepEquals, []params.CloudImageMetadataList{
				{[]params.CloudImageMetadata{m, m}},
			})

			c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
			*(result.(*params.ErrorResults)) = params.ErrorResults{
				Results: []params.ErrorResult{{}},
			}

			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	err := client.Save([]params.CloudImageMetadata{m, m})
	c.Check(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
}
コード例 #6
0
ファイル: package_test.go プロジェクト: howbazaar/juju
func (s *baseMetadataSuite) ImageClient(done chan struct{}) *imagemetadata.Client {
	closer := apitesting.APICallerFunc(func(objType string, version int, id, request string, a, result interface{}) error {
		s.apiCalled = false
		if request == "UpdateFromPublishedImages" {
			s.apiCalled = true
			close(done)
			return nil
		}
		return nil
	})

	return imagemetadata.NewClient(closer)
}
コード例 #7
0
ファイル: client_test.go プロジェクト: imoapps/juju
func (s *imagemetadataSuite) TestSaveFacadeCallError(c *gc.C) {
	m := []params.CloudImageMetadata{{}}
	msg := "facade failure"
	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Save")
			return errors.New(msg)
		})
	client := imagemetadata.NewClient(apiCaller)
	err := client.Save(m)
	c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
}
コード例 #8
0
ファイル: client_test.go プロジェクト: kakamessi99/juju
func (s *imagemetadataSuite) TestUpdateFromPublishedImagesFacadeCallError(c *gc.C) {
	called := false
	msg := "facade failure"
	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "UpdateFromPublishedImages")
			return errors.New(msg)
		})
	client := imagemetadata.NewClient(apiCaller)
	err := client.UpdateFromPublishedImages()
	c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
	c.Assert(called, jc.IsTrue)
}
コード例 #9
0
ファイル: client_test.go プロジェクト: kakamessi99/juju
func (s *imagemetadataSuite) TestUpdateFromPublishedImages(c *gc.C) {
	called := false

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "UpdateFromPublishedImages")
			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	err := client.UpdateFromPublishedImages()
	c.Check(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
}
コード例 #10
0
ファイル: client_test.go プロジェクト: kakamessi99/juju
func (s *imagemetadataSuite) TestListFacadeCallError(c *gc.C) {
	msg := "facade failure"
	called := false
	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "List")

			return errors.New(msg)
		})
	client := imagemetadata.NewClient(apiCaller)
	found, err := client.List("", "", nil, nil, "", "")
	c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
	c.Assert(found, gc.HasLen, 0)
	c.Assert(called, jc.IsTrue)
}
コード例 #11
0
ファイル: client_test.go プロジェクト: kakamessi99/juju
func (s *imagemetadataSuite) TestSave(c *gc.C) {
	m := params.CloudImageMetadata{}
	called := false

	msg := "save failure"
	expected := []params.ErrorResult{
		params.ErrorResult{},
		params.ErrorResult{&params.Error{Message: msg}},
	}

	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "Save")

			args, ok := a.(params.MetadataSaveParams)
			c.Assert(ok, jc.IsTrue)
			c.Assert(args.Metadata, gc.HasLen, 2)
			c.Assert(args.Metadata, gc.DeepEquals, []params.CloudImageMetadata{m, m})

			if results, k := result.(*params.ErrorResults); k {
				results.Results = expected
			}

			return nil
		})

	client := imagemetadata.NewClient(apiCaller)
	errs, err := client.Save([]params.CloudImageMetadata{m, m})
	c.Check(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
	c.Assert(errs, jc.DeepEquals, expected)
}
コード例 #12
0
func (s *cloudImageMetadataSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

	s.client = imagemetadata.NewClient(s.APIState)
	c.Assert(s.client, gc.NotNil)
}
コード例 #13
0
ファイル: client_test.go プロジェクト: kakamessi99/juju
func (s *imagemetadataSuite) TestList(c *gc.C) {
	// setup data for test
	imageId := "imageid"
	stream := "stream"
	region := "region"
	series := "series"
	arch := "arch"
	virtType := "virt-type"
	rootStorageType := "root-storage-type"
	rootStorageSize := uint64(1024)
	source := "source"

	called := false
	apiCaller := testing.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "ImageMetadata")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "List")

			args, ok := a.(params.ImageMetadataFilter)
			c.Assert(ok, jc.IsTrue)

			if results, k := result.(*params.ListCloudImageMetadataResult); k {
				instances := []params.CloudImageMetadata{
					params.CloudImageMetadata{
						ImageId:         imageId,
						Stream:          args.Stream,
						Region:          args.Region,
						Series:          args.Series[0],
						Arch:            args.Arches[0],
						VirtType:        args.VirtType,
						RootStorageType: args.RootStorageType,
						RootStorageSize: &rootStorageSize,
						Source:          source,
					},
				}
				results.Result = instances
			}

			return nil
		})
	client := imagemetadata.NewClient(apiCaller)
	found, err := client.List(
		stream, region,
		[]string{series}, []string{arch},
		virtType, rootStorageType,
	)
	c.Check(err, jc.ErrorIsNil)

	c.Assert(called, jc.IsTrue)
	expected := []params.CloudImageMetadata{
		params.CloudImageMetadata{
			ImageId:         imageId,
			Stream:          stream,
			Region:          region,
			Series:          series,
			Arch:            arch,
			VirtType:        virtType,
			RootStorageType: rootStorageType,
			RootStorageSize: &rootStorageSize,
			Source:          source,
		},
	}
	c.Assert(found, jc.DeepEquals, expected)
}
コード例 #14
0
ファイル: state.go プロジェクト: snailwalker/juju
// MetadataUpdater returns access to the imageMetadata API
func (st *state) MetadataUpdater() *imagemetadata.Client {
	return imagemetadata.NewClient(st)
}