本文整理汇总了Golang中github.com/juju/juju/api/addresser.NewAPI函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAPI函数的具体用法?Golang NewAPI怎么用?Golang NewAPI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAPI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
}
示例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)
}
示例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)
}
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}