// NewState creates a new client-side Firewaller API facade. func NewState(caller base.APICaller) *State { facadeCaller := base.NewFacadeCaller(caller, firewallerFacade) return &State{ facade: facadeCaller, ModelWatcher: common.NewModelWatcher(facadeCaller), CloudSpecAPI: cloudspec.NewCloudSpecAPI(facadeCaller), } }
// NewState returns a version of the state that provides functionality // required by agent code. func NewState(caller base.APICaller) *State { facadeCaller := base.NewFacadeCaller(caller, "Agent") return &State{ facade: facadeCaller, ModelWatcher: common.NewModelWatcher(facadeCaller), CloudSpecAPI: cloudspec.NewCloudSpecAPI(facadeCaller), ControllerConfigAPI: common.NewControllerConfig(facadeCaller), } }
func (s *CloudSpecSuite) TestCloudSpecResultCountMismatch(c *gc.C) { facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { return nil } api := cloudspec.NewCloudSpecAPI(&facadeCaller) _, err := api.CloudSpec(coretesting.ModelTag) c.Assert(err, gc.ErrorMatches, "expected 1 result, got 0") }
// NewClient creates a new `Client` based on an existing authenticated API // connection. func NewClient(st base.APICallCloser) *Client { frontend, backend := base.NewClientFacade(st, "Controller") return &Client{ ClientFacade: frontend, facade: backend, ControllerConfigAPI: common.NewControllerConfig(backend), CloudSpecAPI: cloudspec.NewCloudSpecAPI(backend), } }
func (s *CloudSpecSuite) TestCloudSpecOverallError(c *gc.C) { expect := errors.New("bewm") facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { return expect } api := cloudspec.NewCloudSpecAPI(&facadeCaller) _, err := api.CloudSpec(coretesting.ModelTag) c.Assert(err, gc.Equals, expect) }
func (s *CloudSpecSuite) TestCloudSpecInvalidCloudSpec(c *gc.C) { facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { *(response.(*params.CloudSpecResults)) = params.CloudSpecResults{[]params.CloudSpecResult{{ Result: ¶ms.CloudSpec{ Type: "", }, }}} return nil } api := cloudspec.NewCloudSpecAPI(&facadeCaller) _, err := api.CloudSpec(coretesting.ModelTag) c.Assert(err, gc.ErrorMatches, "validating CloudSpec: empty Type not valid") }
func (s *CloudSpecSuite) TestCloudSpecResultError(c *gc.C) { facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { *(response.(*params.CloudSpecResults)) = params.CloudSpecResults{ []params.CloudSpecResult{{ Error: ¶ms.Error{ Code: params.CodeUnauthorized, Message: "dang", }, }}, } return nil } api := cloudspec.NewCloudSpecAPI(&facadeCaller) _, err := api.CloudSpec(coretesting.ModelTag) c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized) c.Assert(err, gc.ErrorMatches, "API request failed: dang") }
func (s *CloudSpecSuite) TestCloudSpec(c *gc.C) { facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}} facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error { c.Assert(name, gc.Equals, "CloudSpec") c.Assert(args, jc.DeepEquals, params.Entities{[]params.Entity{ {coretesting.ModelTag.String()}, }}) *(response.(*params.CloudSpecResults)) = params.CloudSpecResults{ []params.CloudSpecResult{{ Result: ¶ms.CloudSpec{ Type: "type", Name: "name", Region: "region", Endpoint: "endpoint", IdentityEndpoint: "identity-endpoint", StorageEndpoint: "storage-endpoint", Credential: ¶ms.CloudCredential{ AuthType: "auth-type", Attributes: map[string]string{"k": "v"}, }, }, }}, } return nil } api := cloudspec.NewCloudSpecAPI(&facadeCaller) cloudSpec, err := api.CloudSpec(coretesting.ModelTag) c.Assert(err, jc.ErrorIsNil) credential := cloud.NewCredential( "auth-type", map[string]string{"k": "v"}, ) c.Assert(cloudSpec, jc.DeepEquals, environs.CloudSpec{ Type: "type", Name: "name", Region: "region", Endpoint: "endpoint", IdentityEndpoint: "identity-endpoint", StorageEndpoint: "storage-endpoint", Credential: &credential, }) }
func (s *CloudSpecSuite) TestNewCloudSpecAPI(c *gc.C) { api := cloudspec.NewCloudSpecAPI(nil) c.Check(api, gc.NotNil) }