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

Golang addresser.NewAPI函数代码示例

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

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



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

示例1: TestIPAddressesServerError

func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
		},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{
			{params.Alive, nil},
			{"", apiservertesting.ServerError("server failure")},
		},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddresses, err := api.IPAddresses(tag1, tag2)
	c.Assert(len(ipAddresses), gc.Equals, 2)
	c.Assert(ipAddresses[0].Tag().String(), gc.Equals, tag1.String())
	c.Assert(ipAddresses[1], gc.IsNil)
	c.Assert(err, gc.Equals, common.ErrPartialResults)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:27,代码来源:addresser_test.go


示例2: TestIPAddressesSuccess

func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
	tests := []struct {
		tag  names.IPAddressTag
		life params.Life
	}{
		{names.NewIPAddressTag("11111111-0000-0000-0000-000000000000"), params.Alive},
		{names.NewIPAddressTag("22222222-0000-0000-0000-000000000000"), params.Dying},
		{names.NewIPAddressTag("33333333-0000-0000-0000-000000000000"), params.Dead},
	}
	for _, test := range tests {
		var called int
		args := params.Entities{
			Entities: []params.Entity{{Tag: test.tag.String()}},
		}
		results := params.LifeResults{
			Results: []params.LifeResult{{test.life, nil}},
		}
		apiCaller := successAPICaller(c, "Life", args, results, &called)
		api := addresser.NewAPI(apiCaller)

		ipAddress, err := api.IPAddress(test.tag)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(called, gc.Equals, 1)
		c.Check(ipAddress.Tag(), gc.Equals, test.tag)
		c.Check(ipAddress.Life(), gc.Equals, test.life)
	}
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:27,代码来源:addresser_test.go


示例3: TestWatchIPAddressesSuccess

func (s *AddresserSuite) TestWatchIPAddressesSuccess(c *gc.C) {
	var numFacadeCalls int
	var numWatcherCalls int
	expectedResult := params.EntitiesWatchResult{
		EntitiesWatcherId: "42",
		Changes: []string{
			"ipaddress-11111111-0000-0000-0000-000000000000",
			"ipaddress-22222222-0000-0000-0000-000000000000",
		},
	}
	watcherFunc := func(caller base.APICaller, result params.EntitiesWatchResult) watcher.EntitiesWatcher {
		numWatcherCalls++
		c.Check(caller, gc.NotNil)
		c.Check(result, jc.DeepEquals, expectedResult)
		return nil
	}
	s.PatchValue(addresser.NewEntitiesWatcher, watcherFunc)

	apiCaller := successAPICaller(c, "WatchIPAddresses", nil, expectedResult, &numFacadeCalls)
	api := addresser.NewAPI(apiCaller)

	w, err := api.WatchIPAddresses()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(numFacadeCalls, gc.Equals, 1)
	c.Assert(numWatcherCalls, gc.Equals, 1)
	c.Assert(w, gc.IsNil)
}
开发者ID:exekias,项目名称:juju,代码行数:27,代码来源:addresser_test.go


示例4: TestIPAddressesSuccess

func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
	tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
			{Tag: tag3.String()},
		},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{
			{Life: params.Alive},
			{Life: params.Dying},
			{Life: params.Dead},
		},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddresses, err := api.IPAddresses(tag1, tag2, tag3)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
	c.Assert(len(ipAddresses), gc.Equals, 3)
	for i, ipAddress := range ipAddresses {
		c.Check(ipAddress.Tag().String(), gc.Equals, args.Entities[i].Tag)
		c.Check(ipAddress.Life(), gc.Equals, results.Results[i].Life)
	}
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:32,代码来源:addresser_test.go


示例5: TestRemoveSuccess

func (s *AddresserSuite) TestRemoveSuccess(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
	tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
			{Tag: tag3.String()},
		},
	}
	results := params.ErrorResults{
		Results: []params.ErrorResult{{nil}, {nil}, {nil}},
	}
	apiCaller := successAPICaller(c, "Remove", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress1 := addresser.NewIPAddress(api, tag1, params.Alive)
	ipAddress2 := addresser.NewIPAddress(api, tag2, params.Dying)
	ipAddress3 := addresser.NewIPAddress(api, tag3, params.Dead)

	err := api.Remove(ipAddress1, ipAddress2, ipAddress3)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:27,代码来源:addresser_test.go


示例6: manifoldStart

// manifoldStart creates an addresser worker, given a base.APICaller.
func manifoldStart(apiCaller base.APICaller) (worker.Worker, error) {
	api := addresser.NewAPI(apiCaller)
	w, err := NewWorker(api)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}
开发者ID:felicianotech,项目名称:juju,代码行数:9,代码来源:manifold.go


示例7: TestEnvironConfigClientError

func (s *AddresserSuite) TestEnvironConfigClientError(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "EnvironConfig", nil, &called)
	api := addresser.NewAPI(apiCaller)

	cfg, err := api.EnvironConfig()
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(cfg, gc.IsNil)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:10,代码来源:addresser_test.go


示例8: TestCleanupIPAddressesSuccess

func (s *AddresserSuite) TestCleanupIPAddressesSuccess(c *gc.C) {
	var called int
	expectedResult := params.ErrorResult{}
	apiCaller := successAPICaller(c, "CleanupIPAddresses", nil, expectedResult, &called)
	api := addresser.NewAPI(apiCaller)

	err := api.CleanupIPAddresses()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:10,代码来源:addresser_test.go


示例9: TestIPAddressesClientError

func (s *AddresserSuite) TestIPAddressesClientError(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(ipAddress, gc.IsNil)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:10,代码来源:addresser_test.go


示例10: TestWatchIPAddressesClientError

func (s *AddresserSuite) TestWatchIPAddressesClientError(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "WatchIPAddresses", nil, &called)

	api := addresser.NewAPI(apiCaller)
	w, err := api.WatchIPAddresses()

	c.Assert(w, jc.ErrorIsNil)
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:11,代码来源:addresser_test.go


示例11: TestRemoveClientError

func (s *AddresserSuite) TestRemoveClientError(c *gc.C) {
	var called int
	tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
	apiCaller := clientErrorAPICaller(c, "Remove", nil, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress := addresser.NewIPAddress(api, tag, params.Alive)
	err := ipAddress.Remove()
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:11,代码来源:addresser_test.go


示例12: TestNewAPI

func (s *AddresserSuite) TestNewAPI(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "CleanupIPAddresses", nil, &called)
	api := addresser.NewAPI(apiCaller)
	c.Check(api, gc.NotNil)
	c.Check(called, gc.Equals, 0)

	// Make a call so that an error will be returned.
	err := api.CleanupIPAddresses()
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:12,代码来源:addresser_test.go


示例13: TestCleanupIPAddressesServerError

func (s *AddresserSuite) TestCleanupIPAddressesServerError(c *gc.C) {
	var called int
	expectedResult := params.ErrorResult{
		Error: apiservertesting.ServerError("server boom!"),
	}
	apiCaller := successAPICaller(c, "CleanupIPAddresses", nil, expectedResult, &called)
	api := addresser.NewAPI(apiCaller)

	err := api.CleanupIPAddresses()
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:12,代码来源:addresser_test.go


示例14: TestWatchIPAddressesServerError

func (s *AddresserSuite) TestWatchIPAddressesServerError(c *gc.C) {
	var called int
	expectedResult := params.EntitiesWatchResult{
		Error: apiservertesting.ServerError("server boom!"),
	}
	apiCaller := successAPICaller(c, "WatchIPAddresses", nil, expectedResult, &called)
	api := addresser.NewAPI(apiCaller)

	w, err := api.WatchIPAddresses()
	c.Assert(w, jc.ErrorIsNil)
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:13,代码来源:addresser_test.go


示例15: TestEnvironConfigServerError

func (s *AddresserSuite) TestEnvironConfigServerError(c *gc.C) {
	var called int
	expectResults := params.EnvironConfigResult{
		Config: params.EnvironConfig{"type": "foo"},
	}
	apiCaller := successAPICaller(c, "EnvironConfig", nil, expectResults, &called)
	api := addresser.NewAPI(apiCaller)

	cfg, err := api.EnvironConfig()
	c.Assert(err, gc.NotNil)
	c.Assert(called, gc.Equals, 1)
	c.Assert(cfg, gc.IsNil)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:13,代码来源:addresser_test.go


示例16: TestCanDeallocateAddressesServerError

func (s *AddresserSuite) TestCanDeallocateAddressesServerError(c *gc.C) {
	var called int
	expectedResult := params.BoolResult{
		Error: apiservertesting.ServerError("server boom!"),
	}
	apiCaller := successAPICaller(c, "CanDeallocateAddresses", nil, expectedResult, &called)
	api := addresser.NewAPI(apiCaller)

	ok, err := api.CanDeallocateAddresses()
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(ok, jc.IsFalse)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:13,代码来源:addresser_test.go


示例17: TestCanDeallocateAddressesSuccess

func (s *AddresserSuite) TestCanDeallocateAddressesSuccess(c *gc.C) {
	var called int
	expectedResult := params.BoolResult{
		Result: true,
	}
	apiCaller := successAPICaller(c, "CanDeallocateAddresses", nil, expectedResult, &called)
	api := addresser.NewAPI(apiCaller)

	ok, err := api.CanDeallocateAddresses()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsTrue)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:13,代码来源:addresser_test.go


示例18: TestNewAPISuccess

func (s *AddresserSuite) TestNewAPISuccess(c *gc.C) {
	var called int
	// IPAddress below uses common.Life for implementation.
	apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
	api := addresser.NewAPI(apiCaller)
	c.Check(api, gc.NotNil)
	c.Check(called, gc.Equals, 0)

	// Make a call so that an error will be returned.
	addresses, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(addresses, gc.IsNil)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:14,代码来源:addresser_test.go


示例19: TestEnvironConfigSuccess

func (s *AddresserSuite) TestEnvironConfigSuccess(c *gc.C) {
	var called int
	expectedConfig := coretesting.EnvironConfig(c)
	expectedResults := params.EnvironConfigResult{
		Config: params.EnvironConfig(expectedConfig.AllAttrs()),
	}
	apiCaller := successAPICaller(c, "EnvironConfig", nil, expectedResults, &called)
	api := addresser.NewAPI(apiCaller)

	cfg, err := api.EnvironConfig()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
	c.Assert(cfg, jc.DeepEquals, expectedConfig)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:14,代码来源:addresser_test.go


示例20: TestIPAddressesServerError

func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
	var called int
	tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
	args := params.Entities{
		Entities: []params.Entity{{Tag: tag.String()}},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{{"", apiservertesting.ServerError("server boom!")}},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress, err := api.IPAddress(tag)
	c.Assert(ipAddress, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(called, gc.Equals, 1)
}
开发者ID:frankban,项目名称:juju-tmp,代码行数:17,代码来源:addresser_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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