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) }
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) } }
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) }
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) } }
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) }
// 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 }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
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) }
func (s *AddresserSuite) TestRemoveServerError(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.ErrorResults{ Results: []params.ErrorResult{{apiservertesting.ServerError("server boom!")}}, } apiCaller := successAPICaller(c, "Remove", args, results, &called) api := addresser.NewAPI(apiCaller) ipAddress := addresser.NewIPAddress(api, tag, params.Alive) err := ipAddress.Remove() c.Assert(err, gc.ErrorMatches, "server boom!") c.Assert(called, gc.Equals, 1) }
// Addresser returns access to the Addresser API. func (st *state) Addresser() *addresser.API { return addresser.NewAPI(st) }
func (s *AddresserSuite) TestNewAPIWithNilCaller(c *gc.C) { panicFunc := func() { addresser.NewAPI(nil) } c.Assert(panicFunc, gc.PanicMatches, "caller is nil") }