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") }
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, }) }