• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang imagemetadata.NewClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/api/imagemetadata.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewClient函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestDeleteFailure

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)
}
开发者ID:imoapps,项目名称:juju,代码行数:27,代码来源:client_test.go


示例2: NewImageMetadataAPI

// 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
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:cloudimagemetadata.go


示例3: TestDeleteMultipleResult

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)
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:client_test.go


示例4: TestDelete

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)
}
开发者ID:imoapps,项目名称:juju,代码行数:28,代码来源:client_test.go


示例5: TestSave

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)
}
开发者ID:imoapps,项目名称:juju,代码行数:35,代码来源:client_test.go


示例6: ImageClient

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)
}
开发者ID:howbazaar,项目名称:juju,代码行数:13,代码来源:package_test.go


示例7: TestSaveFacadeCallError

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)
}
开发者ID:imoapps,项目名称:juju,代码行数:18,代码来源:client_test.go


示例8: TestUpdateFromPublishedImagesFacadeCallError

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)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:20,代码来源:client_test.go


示例9: TestUpdateFromPublishedImages

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)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:21,代码来源:client_test.go


示例10: TestListFacadeCallError

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)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:22,代码来源:client_test.go


示例11: TestSave

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)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:39,代码来源:client_test.go


示例12: SetUpTest

func (s *cloudImageMetadataSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

	s.client = imagemetadata.NewClient(s.APIState)
	c.Assert(s.client, gc.NotNil)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:6,代码来源:cloudimagemetadata_test.go


示例13: TestList

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)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:70,代码来源:client_test.go


示例14: MetadataUpdater

// MetadataUpdater returns access to the imageMetadata API
func (st *state) MetadataUpdater() *imagemetadata.Client {
	return imagemetadata.NewClient(st)
}
开发者ID:snailwalker,项目名称:juju,代码行数:4,代码来源:state.go



注:本文中的github.com/juju/juju/api/imagemetadata.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang instancepoller.NewAPI函数代码示例发布时间:2022-05-23
下一篇:
Golang firewaller.Unit类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap