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

Golang client.NewClient函数代码示例

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

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



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

示例1: TestTooMany

func (s *ListResourcesSuite) TestTooMany(c *gc.C) {
	s.facade.FacadeCallFn = func(_ string, _, response interface{}) error {
		typedResponse, ok := response.(*api.ResourcesResults)
		c.Assert(ok, jc.IsTrue)

		typedResponse.Results = []api.ResourcesResult{{
			Resources: nil,
		}, {
			Resources: nil,
		}, {
			Resources: nil,
		}}

		return nil
	}

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service", "other-service"}
	results, err := cl.ListResources(services)

	c.Check(results, gc.HasLen, 0)
	c.Check(err, gc.ErrorMatches, `.*got invalid data from server \(expected 2 results, got 3\).*`)
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:25,代码来源:client_listresources_test.go


示例2: TestBulk

func (s *ListResourcesSuite) TestBulk(c *gc.C) {
	expected1, apiResult1 := newResourceResult(c, "a-service", "spam")
	s.facade.apiResults["a-service"] = apiResult1
	expected2, apiResult2 := newResourceResult(c, "other-service", "eggs", "ham")
	s.facade.apiResults["other-service"] = apiResult2

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service", "other-service"}
	results, err := cl.ListResources(services)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []resource.ServiceResources{
		{Resources: expected1},
		{Resources: expected2},
	})
	c.Check(s.stub.Calls(), gc.HasLen, 1)
	s.stub.CheckCall(c, 0, "FacadeCall",
		"ListResources",
		&api.ListResourcesArgs{[]params.Entity{
			{
				Tag: "service-a-service",
			}, {
				Tag: "service-other-service",
			},
		}},
		&api.ResourcesResults{
			Results: []api.ResourcesResult{
				apiResult1,
				apiResult2,
			},
		},
	)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:34,代码来源:client_listresources_test.go


示例3: TestPendingOkay

func (s *UploadSuite) TestPendingOkay(c *gc.C) {
	res, apiResult := newResourceResult(c, "a-service", "spam")
	uuid, err := utils.NewUUID()
	c.Assert(err, jc.ErrorIsNil)
	expected := uuid.String()
	s.response.Resource = apiResult.Resources[0]
	data := "<data>"
	fp, err := charmresource.GenerateFingerprint(strings.NewReader(data))
	c.Assert(err, jc.ErrorIsNil)
	req, err := http.NewRequest("PUT", "/services/a-service/resources/spam", nil)
	c.Assert(err, jc.ErrorIsNil)
	req.Header.Set("Content-Type", "application/octet-stream")
	req.Header.Set("Content-SHA384", fp.String())
	req.Header.Set("Content-Length", fmt.Sprint(len(data)))
	req.ContentLength = int64(len(data))
	req.URL.RawQuery = "pendingid=" + expected
	reader := &stubFile{stub: s.stub}
	reader.returnRead = strings.NewReader(data)
	s.facade.pendingIDs = []string{expected}
	cl := client.NewClient(s.facade, s, s.facade)

	uploadID, err := cl.AddPendingResource("a-service", res[0].Resource, reader)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c,
		"FacadeCall",
		"Read",
		"Read",
		"Seek",
		"Do",
	)
	s.stub.CheckCall(c, 4, "Do", req, reader, s.response)
	c.Check(uploadID, gc.Equals, expected)
}
开发者ID:OSBI,项目名称:juju,代码行数:34,代码来源:client_upload_test.go


示例4: TestOkay

func (s *ListResourcesSuite) TestOkay(c *gc.C) {
	expected, apiResult := newResourceResult(c, "a-application", "spam")
	s.facade.apiResults["a-application"] = apiResult

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-application"}
	results, err := cl.ListResources(services)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []resource.ServiceResources{
		{Resources: expected},
	})
	c.Check(s.stub.Calls(), gc.HasLen, 1)
	s.stub.CheckCall(c, 0, "FacadeCall",
		"ListResources",
		&api.ListResourcesArgs{[]params.Entity{{
			Tag: "application-a-application",
		}}},
		&api.ResourcesResults{
			Results: []api.ResourcesResult{
				apiResult,
			},
		},
	)
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:client_listresources_test.go


示例5: TestBadService

func (s *UploadSuite) TestBadService(c *gc.C) {
	cl := client.NewClient(s.facade, s, s.facade)

	err := cl.Upload("???", "spam", nil)

	c.Check(err, gc.ErrorMatches, `.*invalid service.*`)
	s.stub.CheckNoCalls(c)
}
开发者ID:OSBI,项目名称:juju,代码行数:8,代码来源:client_upload_test.go


示例6: TestBadServices

func (s *ListResourcesSuite) TestBadServices(c *gc.C) {
	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"???"}
	_, err := cl.ListResources(services)

	c.Check(err, gc.ErrorMatches, `.*invalid service.*`)
	s.stub.CheckNoCalls(c)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:client_listresources_test.go


示例7: TestServiceNotFound

func (s *ListResourcesSuite) TestServiceNotFound(c *gc.C) {
	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service"}
	_, err := cl.ListResources(services)

	c.Check(err, jc.Satisfies, errors.IsNotFound)
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:client_listresources_test.go


示例8: TestNoServices

func (s *ListResourcesSuite) TestNoServices(c *gc.C) {
	cl := client.NewClient(s.facade, s, s.facade)

	var services []string
	results, err := cl.ListResources(services)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, gc.HasLen, 0)
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:10,代码来源:client_listresources_test.go


示例9: TestPendingBadService

func (s *UploadSuite) TestPendingBadService(c *gc.C) {
	res, _ := newResourceResult(c, "a-service", "spam")
	s.facade.FacadeCallFn = nil
	cl := client.NewClient(s.facade, s, s.facade)

	_, err := cl.AddPendingResource("???", res[0].Resource, nil)

	c.Check(err, gc.ErrorMatches, `.*invalid service.*`)
	s.stub.CheckNoCalls(c)
}
开发者ID:OSBI,项目名称:juju,代码行数:10,代码来源:client_upload_test.go


示例10: newAPIClient

func newAPIClient(apiCaller api.Connection) (*client.Client, error) {
	caller := base.NewFacadeCallerForVersion(apiCaller, resource.ComponentName, server.Version)

	httpClient, err := apiCaller.HTTPClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	// The apiCaller takes care of prepending /environment/<envUUID>.
	apiClient := client.NewClient(caller, httpClient, apiCaller)
	return apiClient, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:11,代码来源:apiclient.go


示例11: TestBadRequest

func (s *UploadSuite) TestBadRequest(c *gc.C) {
	reader := &stubFile{stub: s.stub}
	cl := client.NewClient(s.facade, s, s.facade)
	failure := errors.New("<failure>")
	s.stub.SetErrors(failure)

	err := cl.Upload("a-service", "spam", reader)

	c.Check(errors.Cause(err), gc.Equals, failure)
	s.stub.CheckCallNames(c, "Read")
}
开发者ID:OSBI,项目名称:juju,代码行数:11,代码来源:client_upload_test.go


示例12: TestRequestFailed

func (s *UploadSuite) TestRequestFailed(c *gc.C) {
	reader := &stubFile{stub: s.stub}
	reader.returnRead = strings.NewReader("<data>")
	cl := client.NewClient(s.facade, s, s.facade)
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, nil, nil, failure)

	err := cl.Upload("a-service", "spam", reader)

	c.Check(errors.Cause(err), gc.Equals, failure)
	s.stub.CheckCallNames(c, "Read", "Read", "Seek", "Do")
}
开发者ID:OSBI,项目名称:juju,代码行数:12,代码来源:client_upload_test.go


示例13: TestServiceEmpty

func (s *ListResourcesSuite) TestServiceEmpty(c *gc.C) {
	s.facade.apiResults["a-service"] = api.ResourcesResult{}

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service"}
	results, err := cl.ListResources(services)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(results, jc.DeepEquals, []resource.ServiceResources{
		{},
	})
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:client_listresources_test.go


示例14: TestServerError

func (s *ListResourcesSuite) TestServerError(c *gc.C) {
	failure := errors.New("<failure>")
	s.facade.FacadeCallFn = func(_ string, _, _ interface{}) error {
		return failure
	}

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service"}
	_, err := cl.ListResources(services)

	c.Check(err, gc.ErrorMatches, `<failure>`)
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:14,代码来源:client_listresources_test.go


示例15: TestPendingBadRequest

func (s *UploadSuite) TestPendingBadRequest(c *gc.C) {
	res, _ := newResource(c, "spam", "", "")
	chRes := res.Resource
	reader := &stubFile{stub: s.stub}
	s.facade.pendingIDs = []string{"some-unique-id"}
	cl := client.NewClient(s.facade, s, s.facade)
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, failure)

	_, err := cl.AddPendingResource("a-service", chRes, reader)

	c.Check(errors.Cause(err), gc.Equals, failure)
	s.stub.CheckCallNames(c, "FacadeCall", "Read")
}
开发者ID:OSBI,项目名称:juju,代码行数:14,代码来源:client_upload_test.go


示例16: TestPendingNoFile

func (s *UploadSuite) TestPendingNoFile(c *gc.C) {
	res, apiResult := newResourceResult(c, "a-service", "spam")
	uuid, err := utils.NewUUID()
	c.Assert(err, jc.ErrorIsNil)
	expected := uuid.String()
	s.response.Resource = apiResult.Resources[0]
	s.facade.pendingIDs = []string{expected}
	cl := client.NewClient(s.facade, s, s.facade)

	uploadID, err := cl.AddPendingResource("a-service", res[0].Resource, nil)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c,
		"FacadeCall",
	)
	c.Check(uploadID, gc.Equals, expected)
}
开发者ID:OSBI,项目名称:juju,代码行数:17,代码来源:client_upload_test.go


示例17: TestPendingRequestFailed

func (s *UploadSuite) TestPendingRequestFailed(c *gc.C) {
	res, _ := newResourceResult(c, "a-service", "spam")
	reader := &stubFile{stub: s.stub}
	reader.returnRead = strings.NewReader("<data>")
	s.facade.pendingIDs = []string{"some-unique-id"}
	cl := client.NewClient(s.facade, s, s.facade)
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, nil, nil, nil, failure)

	_, err := cl.AddPendingResource("a-service", res[0].Resource, reader)

	c.Check(errors.Cause(err), gc.Equals, failure)
	s.stub.CheckCallNames(c,
		"FacadeCall",
		"Read",
		"Read",
		"Seek",
		"Do",
	)
}
开发者ID:OSBI,项目名称:juju,代码行数:20,代码来源:client_upload_test.go


示例18: TestOkay

func (s *UploadSuite) TestOkay(c *gc.C) {
	data := "<data>"
	_, s.response.Resource = newResource(c, "spam", "a-user", data)
	fp, err := charmresource.GenerateFingerprint(strings.NewReader(data))
	c.Assert(err, jc.ErrorIsNil)
	req, err := http.NewRequest("PUT", "/services/a-service/resources/spam", nil)
	c.Assert(err, jc.ErrorIsNil)
	req.Header.Set("Content-Type", "application/octet-stream")
	req.Header.Set("Content-SHA384", fp.String())
	req.Header.Set("Content-Length", fmt.Sprint(len(data)))
	req.ContentLength = int64(len(data))
	reader := &stubFile{stub: s.stub}
	reader.returnRead = strings.NewReader(data)
	cl := client.NewClient(s.facade, s, s.facade)

	err = cl.Upload("a-service", "spam", reader)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Read", "Read", "Seek", "Do")
	s.stub.CheckCall(c, 3, "Do", req, reader, s.response)
}
开发者ID:OSBI,项目名称:juju,代码行数:21,代码来源:client_upload_test.go


示例19: TestConversionFailed

func (s *ListResourcesSuite) TestConversionFailed(c *gc.C) {
	s.facade.FacadeCallFn = func(_ string, _, response interface{}) error {
		typedResponse, ok := response.(*api.ResourcesResults)
		c.Assert(ok, jc.IsTrue)

		var res api.Resource
		res.Name = "spam"
		typedResponse.Results = []api.ResourcesResult{{
			Resources: []api.Resource{
				res,
			},
		}}

		return nil
	}

	cl := client.NewClient(s.facade, s, s.facade)

	services := []string{"a-service"}
	_, err := cl.ListResources(services)

	c.Check(err, gc.ErrorMatches, `.*got bad data.*`)
	s.stub.CheckCallNames(c, "FacadeCall")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:24,代码来源:client_listresources_test.go


示例20: TestPendingResources

func (s *UploadSuite) TestPendingResources(c *gc.C) {
	res, apiResult := newResourceResult(c, "a-service", "spam")
	resources := []charmresource.Resource{res[0].Resource}
	uuid, err := utils.NewUUID()
	c.Assert(err, jc.ErrorIsNil)
	expected := []string{uuid.String()}
	s.response.Resource = apiResult.Resources[0]
	s.facade.pendingIDs = expected
	cURL := charm.MustParseURL("cs:~a-user/trusty/spam-5")
	cl := client.NewClient(s.facade, s, s.facade)

	pendingIDs, err := cl.AddPendingResources(client.AddPendingResourcesArgs{
		ServiceID: "a-service",
		CharmID: charmstore.CharmID{
			URL: cURL,
		},
		Resources: resources,
	})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "FacadeCall")
	//s.stub.CheckCall(c, 0, "FacadeCall", "AddPendingResources", args, result)
	c.Check(pendingIDs, jc.DeepEquals, expected)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:24,代码来源:client_upload_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang server.NewFacade函数代码示例发布时间:2022-05-23
下一篇:
Golang resource.ServiceResources类代码示例发布时间: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