How to use NewClient method of cloudapi Package

Best K6 code snippet using cloudapi.NewClient

cloud_test.go

Source:cloud_test.go Github

copy

Full Screen

...50 s.called = true51 return nil52 },53 )54 client := cloudapi.NewClient(apiCaller)55 result, err := client.Cloud(names.NewCloudTag("foo"))56 c.Assert(err, jc.ErrorIsNil)57 c.Assert(result, jc.DeepEquals, cloud.Cloud{58 Name: "foo",59 Type: "dummy",60 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},61 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},62 })63 c.Assert(s.called, jc.IsTrue)64}65func (s *cloudSuite) TestCloudInfo(c *gc.C) {66 apiCaller := basetesting.APICallerFunc(67 func(objType string,68 version int,69 id, request string,70 a, result interface{},71 ) error {72 c.Check(objType, gc.Equals, "Cloud")73 c.Check(id, gc.Equals, "")74 c.Check(request, gc.Equals, "CloudInfo")75 c.Check(a, jc.DeepEquals, params.Entities{76 Entities: []params.Entity{77 {Tag: "cloud-foo"}, {Tag: "cloud-bar"},78 },79 })80 c.Assert(result, gc.FitsTypeOf, &params.CloudInfoResults{})81 results := result.(*params.CloudInfoResults)82 results.Results = []params.CloudInfoResult{{83 Result: &params.CloudInfo{84 CloudDetails: params.CloudDetails{85 Type: "dummy",86 AuthTypes: []string{"empty", "userpass"},87 Regions: []params.CloudRegion{{Name: "nether", Endpoint: "endpoint"}},88 },89 Users: []params.CloudUserInfo{{90 UserName: "fred",91 DisplayName: "Fred",92 Access: "admin",93 }, {94 UserName: "bob",95 DisplayName: "Bob",96 Access: "add-model",97 }},98 },99 }, {100 Result: &params.CloudInfo{101 CloudDetails: params.CloudDetails{102 Type: "dummy",103 AuthTypes: []string{"empty", "userpass"},104 Regions: []params.CloudRegion{{Name: "nether", Endpoint: "endpoint"}},105 },106 Users: []params.CloudUserInfo{{107 UserName: "mary",108 DisplayName: "Mary",109 Access: "admin",110 }},111 },112 }}113 s.called = true114 return nil115 },116 )117 client := cloudapi.NewClient(apiCaller)118 result, err := client.CloudInfo([]names.CloudTag{119 names.NewCloudTag("foo"),120 names.NewCloudTag("bar"),121 })122 c.Assert(err, jc.ErrorIsNil)123 c.Assert(result, jc.DeepEquals, []cloudapi.CloudInfo{{124 Cloud: cloud.Cloud{125 Name: "foo",126 Type: "dummy",127 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},128 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},129 },130 Users: map[string]cloudapi.CloudUserInfo{131 "bob": {132 DisplayName: "Bob",133 Access: "add-model",134 },135 "fred": {136 DisplayName: "Fred",137 Access: "admin",138 },139 },140 }, {141 Cloud: cloud.Cloud{142 Name: "bar",143 Type: "dummy",144 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},145 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},146 },147 Users: map[string]cloudapi.CloudUserInfo{148 "mary": {149 DisplayName: "Mary",150 Access: "admin",151 },152 },153 }})154 c.Assert(s.called, jc.IsTrue)155}156func (s *cloudSuite) TestClouds(c *gc.C) {157 apiCaller := basetesting.APICallerFunc(158 func(objType string,159 version int,160 id, request string,161 a, result_ interface{},162 ) error {163 c.Check(objType, gc.Equals, "Cloud")164 c.Check(id, gc.Equals, "")165 c.Check(request, gc.Equals, "Clouds")166 c.Check(a, gc.IsNil)167 c.Assert(result_, gc.FitsTypeOf, &params.CloudsResult{})168 result := result_.(*params.CloudsResult)169 result.Clouds = map[string]params.Cloud{170 "cloud-foo": {171 Type: "bar",172 },173 "cloud-baz": {174 Type: "qux",175 AuthTypes: []string{"empty", "userpass"},176 Regions: []params.CloudRegion{{Name: "nether", Endpoint: "endpoint"}},177 },178 }179 s.called = true180 return nil181 },182 )183 client := cloudapi.NewClient(apiCaller)184 clouds, err := client.Clouds()185 c.Assert(err, jc.ErrorIsNil)186 c.Assert(clouds, jc.DeepEquals, map[names.CloudTag]cloud.Cloud{187 names.NewCloudTag("foo"): {188 Name: "foo",189 Type: "bar",190 },191 names.NewCloudTag("baz"): {192 Name: "baz",193 Type: "qux",194 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},195 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},196 },197 })198 c.Assert(s.called, jc.IsTrue)199}200func (s *cloudSuite) TestUserCredentials(c *gc.C) {201 apiCaller := basetesting.APICallerFunc(202 func(objType string,203 version int,204 id, request string,205 a, result interface{},206 ) error {207 c.Check(objType, gc.Equals, "Cloud")208 c.Check(id, gc.Equals, "")209 c.Check(request, gc.Equals, "UserCredentials")210 c.Assert(result, gc.FitsTypeOf, &params.StringsResults{})211 c.Assert(a, jc.DeepEquals, params.UserClouds{UserClouds: []params.UserCloud{{212 UserTag: "user-bob",213 CloudTag: "cloud-foo",214 }}})215 *result.(*params.StringsResults) = params.StringsResults{216 Results: []params.StringsResult{{217 Result: []string{218 "cloudcred-foo_bob_one",219 "cloudcred-foo_bob_two",220 },221 }},222 }223 s.called = true224 return nil225 },226 )227 client := cloudapi.NewClient(apiCaller)228 result, err := client.UserCredentials(names.NewUserTag("bob"), names.NewCloudTag("foo"))229 c.Assert(err, jc.ErrorIsNil)230 c.Assert(result, jc.SameContents, []names.CloudCredentialTag{231 names.NewCloudCredentialTag("foo/bob/one"),232 names.NewCloudCredentialTag("foo/bob/two"),233 })234 c.Assert(s.called, jc.IsTrue)235}236func (s *cloudSuite) TestUpdateCredentialV2(c *gc.C) {237 apiCaller := basetesting.BestVersionCaller{238 APICallerFunc: basetesting.APICallerFunc(239 func(objType string,240 version int,241 id, request string,242 a, result interface{},243 ) error {244 c.Check(objType, gc.Equals, "Cloud")245 c.Check(id, gc.Equals, "")246 c.Check(request, gc.Equals, "UpdateCredentials")247 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})248 c.Assert(a, jc.DeepEquals, params.UpdateCredentialArgs{249 Credentials: []params.TaggedCredential{{250 Tag: "cloudcred-foo_bob_bar",251 Credential: params.CloudCredential{252 AuthType: "userpass",253 Attributes: map[string]string{254 "username": "admin",255 "password": "adm1n",256 },257 },258 }}})259 *result.(*params.ErrorResults) = params.ErrorResults{260 Results: []params.ErrorResult{{}},261 }262 s.called = true263 return nil264 },265 ),266 BestVersion: 2,267 }268 client := cloudapi.NewClient(apiCaller)269 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)270 c.Assert(err, jc.ErrorIsNil)271 c.Assert(result, gc.IsNil)272 c.Assert(s.called, jc.IsTrue)273}274func (s *cloudSuite) TestUpdateCredential(c *gc.C) {275 apiCaller := basetesting.BestVersionCaller{276 APICallerFunc: basetesting.APICallerFunc(277 func(objType string,278 version int,279 id, request string,280 a, result interface{},281 ) error {282 c.Check(objType, gc.Equals, "Cloud")283 c.Check(id, gc.Equals, "")284 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")285 c.Assert(result, gc.FitsTypeOf, &params.UpdateCredentialResults{})286 c.Assert(a, jc.DeepEquals, params.UpdateCredentialArgs{287 Credentials: []params.TaggedCredential{{288 Tag: "cloudcred-foo_bob_bar",289 Credential: params.CloudCredential{290 AuthType: "userpass",291 Attributes: map[string]string{292 "username": "admin",293 "password": "adm1n",294 },295 },296 }}})297 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{298 Results: []params.UpdateCredentialResult{{}},299 }300 s.called = true301 return nil302 },303 ),304 BestVersion: 3,305 }306 client := cloudapi.NewClient(apiCaller)307 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)308 c.Assert(err, jc.ErrorIsNil)309 c.Assert(result, gc.IsNil)310 c.Assert(s.called, jc.IsTrue)311}312func (s *cloudSuite) TestUpdateCredentialErrorV2(c *gc.C) {313 apiCaller := basetesting.BestVersionCaller{314 APICallerFunc: basetesting.APICallerFunc(315 func(objType string,316 version int,317 id, request string,318 a, result interface{},319 ) error {320 c.Check(request, gc.Equals, "UpdateCredentials")321 *result.(*params.ErrorResults) = params.ErrorResults{322 Results: []params.ErrorResult{{apiservererrors.ServerError(errors.New("validation failure"))}},323 }324 s.called = true325 return nil326 },327 ),328 BestVersion: 2,329 }330 client := cloudapi.NewClient(apiCaller)331 errs, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)332 c.Assert(err, gc.ErrorMatches, "validation failure")333 c.Assert(errs, gc.IsNil)334 c.Assert(s.called, jc.IsTrue)335}336func (s *cloudSuite) TestUpdateCredentialError(c *gc.C) {337 apiCaller := basetesting.BestVersionCaller{338 APICallerFunc: basetesting.APICallerFunc(339 func(objType string,340 version int,341 id, request string,342 a, result interface{},343 ) error {344 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")345 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{346 Results: []params.UpdateCredentialResult{347 {CredentialTag: "cloudcred-foo_bob_bar",348 Error: apiservererrors.ServerError(errors.New("validation failure")),349 },350 },351 }352 s.called = true353 return nil354 },355 ),356 BestVersion: 3,357 }358 client := cloudapi.NewClient(apiCaller)359 errs, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)360 c.Assert(err, gc.ErrorMatches, "validation failure")361 c.Assert(errs, gc.IsNil)362 c.Assert(s.called, jc.IsTrue)363}364func (s *cloudSuite) TestUpdateCredentialCallErrorV2(c *gc.C) {365 apiCaller := basetesting.BestVersionCaller{366 APICallerFunc: basetesting.APICallerFunc(367 func(objType string,368 version int,369 id, request string,370 a, result interface{},371 ) error {372 c.Check(request, gc.Equals, "UpdateCredentials")373 s.called = true374 return errors.New("scary but true")375 },376 ),377 BestVersion: 2,378 }379 client := cloudapi.NewClient(apiCaller)380 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)381 c.Assert(err, gc.ErrorMatches, "scary but true")382 c.Assert(result, gc.IsNil)383 c.Assert(s.called, jc.IsTrue)384}385func (s *cloudSuite) TestUpdateCredentialCallError(c *gc.C) {386 apiCaller := basetesting.BestVersionCaller{387 APICallerFunc: basetesting.APICallerFunc(388 func(objType string,389 version int,390 id, request string,391 a, result interface{},392 ) error {393 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")394 s.called = true395 return errors.New("scary but true")396 },397 ),398 BestVersion: 3,399 }400 client := cloudapi.NewClient(apiCaller)401 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)402 c.Assert(err, gc.ErrorMatches, "scary but true")403 c.Assert(result, gc.IsNil)404 c.Assert(s.called, jc.IsTrue)405}406func (s *cloudSuite) TestUpdateCredentialManyResultsV2(c *gc.C) {407 apiCaller := basetesting.BestVersionCaller{408 APICallerFunc: basetesting.APICallerFunc(409 func(objType string,410 version int,411 id, request string,412 a, result interface{},413 ) error {414 c.Check(request, gc.Equals, "UpdateCredentials")415 *result.(*params.ErrorResults) = params.ErrorResults{416 Results: []params.ErrorResult{417 {},418 {},419 },420 }421 s.called = true422 return nil423 },424 ),425 BestVersion: 2,426 }427 client := cloudapi.NewClient(apiCaller)428 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)429 c.Assert(err, gc.ErrorMatches, `expected 1 result got 2 when updating credentials`)430 c.Assert(result, gc.IsNil)431 c.Assert(s.called, jc.IsTrue)432}433func (s *cloudSuite) TestUpdateCredentialManyResults(c *gc.C) {434 apiCaller := basetesting.BestVersionCaller{435 APICallerFunc: basetesting.APICallerFunc(436 func(objType string,437 version int,438 id, request string,439 a, result interface{},440 ) error {441 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")442 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{443 Results: []params.UpdateCredentialResult{444 {},445 {},446 }}447 s.called = true448 return nil449 },450 ),451 BestVersion: 3,452 }453 client := cloudapi.NewClient(apiCaller)454 result, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)455 c.Assert(err, gc.ErrorMatches, `expected 1 result got 2 when updating credentials`)456 c.Assert(result, gc.IsNil)457 c.Assert(s.called, jc.IsTrue)458}459func (s *cloudSuite) TestUpdateCredentialModelErrors(c *gc.C) {460 apiCaller := basetesting.BestVersionCaller{461 APICallerFunc: basetesting.APICallerFunc(462 func(objType string,463 version int,464 id, request string,465 a, result interface{},466 ) error {467 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")468 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{469 Results: []params.UpdateCredentialResult{470 {471 CredentialTag: testCredentialTag.String(),472 Models: []params.UpdateCredentialModelResult{473 {474 ModelUUID: coretesting.ModelTag.Id(),475 ModelName: "test-model",476 Errors: []params.ErrorResult{477 {apiservererrors.ServerError(errors.New("validation failure one"))},478 {apiservererrors.ServerError(errors.New("validation failure two"))},479 },480 },481 },482 },483 }}484 s.called = true485 return nil486 },487 ),488 BestVersion: 3,489 }490 client := cloudapi.NewClient(apiCaller)491 errs, err := client.UpdateCredentialsCheckModels(testCredentialTag, testCredential)492 c.Assert(err, jc.ErrorIsNil)493 c.Assert(errs, gc.DeepEquals, []params.UpdateCredentialModelResult{494 {495 ModelUUID: "deadbeef-0bad-400d-8000-4b1d0d06f00d",496 ModelName: "test-model",497 Errors: []params.ErrorResult{498 {Error: &params.Error{Message: "validation failure one", Code: ""}},499 {Error: &params.Error{Message: "validation failure two", Code: ""}},500 },501 },502 })503 c.Assert(s.called, jc.IsTrue)504}505var (506 testCredentialTag = names.NewCloudCredentialTag("foo/bob/bar")507 testCredential = cloud.NewCredential(cloud.UserPassAuthType, map[string]string{508 "username": "admin",509 "password": "adm1n",510 })511)512func (s *cloudSuite) TestRevokeCredential(c *gc.C) {513 apiCallerF := basetesting.APICallerFunc(514 func(objType string,515 version int,516 id, request string,517 a, result interface{},518 ) error {519 c.Check(objType, gc.Equals, "Cloud")520 c.Check(id, gc.Equals, "")521 c.Check(request, gc.Equals, "RevokeCredentialsCheckModels")522 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})523 c.Assert(a, jc.DeepEquals, params.RevokeCredentialArgs{524 Credentials: []params.RevokeCredentialArg{525 {Tag: "cloudcred-foo_bob_bar", Force: true},526 },527 })528 *result.(*params.ErrorResults) = params.ErrorResults{529 Results: []params.ErrorResult{{}},530 }531 s.called = true532 return nil533 },534 )535 apiCaller := basetesting.BestVersionCaller{536 APICallerFunc: apiCallerF,537 BestVersion: 3,538 }539 client := cloudapi.NewClient(apiCaller)540 tag := names.NewCloudCredentialTag("foo/bob/bar")541 err := client.RevokeCredential(tag, true)542 c.Assert(err, jc.ErrorIsNil)543 c.Assert(s.called, jc.IsTrue)544}545func (s *cloudSuite) TestRevokeCredentialV2(c *gc.C) {546 apiCallerF := basetesting.APICallerFunc(547 func(objType string,548 version int,549 id, request string,550 a, result interface{},551 ) error {552 c.Check(objType, gc.Equals, "Cloud")553 c.Check(id, gc.Equals, "")554 c.Check(request, gc.Equals, "RevokeCredentials")555 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})556 c.Assert(a, jc.DeepEquals, params.Entities{Entities: []params.Entity{{557 Tag: "cloudcred-foo_bob_bar",558 }}})559 *result.(*params.ErrorResults) = params.ErrorResults{560 Results: []params.ErrorResult{{}},561 }562 s.called = true563 return nil564 },565 )566 apiCaller := basetesting.BestVersionCaller{567 APICallerFunc: apiCallerF,568 BestVersion: 2,569 }570 client := cloudapi.NewClient(apiCaller)571 tag := names.NewCloudCredentialTag("foo/bob/bar")572 err := client.RevokeCredential(tag, false)573 c.Assert(err, jc.ErrorIsNil)574 c.Assert(s.called, jc.IsTrue)575}576func (s *cloudSuite) TestCredentials(c *gc.C) {577 apiCaller := basetesting.APICallerFunc(578 func(objType string,579 version int,580 id, request string,581 a, result interface{},582 ) error {583 c.Check(objType, gc.Equals, "Cloud")584 c.Check(id, gc.Equals, "")585 c.Check(request, gc.Equals, "Credential")586 c.Assert(result, gc.FitsTypeOf, &params.CloudCredentialResults{})587 c.Assert(a, jc.DeepEquals, params.Entities{Entities: []params.Entity{{588 Tag: "cloudcred-foo_bob_bar",589 }}})590 *result.(*params.CloudCredentialResults) = params.CloudCredentialResults{591 Results: []params.CloudCredentialResult{592 {593 Result: &params.CloudCredential{594 AuthType: "userpass",595 Attributes: map[string]string{"username": "fred"},596 Redacted: []string{"password"},597 },598 }, {599 Result: &params.CloudCredential{600 AuthType: "userpass",601 Attributes: map[string]string{"username": "mary"},602 Redacted: []string{"password"},603 },604 },605 },606 }607 s.called = true608 return nil609 },610 )611 client := cloudapi.NewClient(apiCaller)612 tag := names.NewCloudCredentialTag("foo/bob/bar")613 result, err := client.Credentials(tag)614 c.Assert(err, jc.ErrorIsNil)615 c.Assert(result, jc.DeepEquals, []params.CloudCredentialResult{616 {617 Result: &params.CloudCredential{618 AuthType: "userpass",619 Attributes: map[string]string{"username": "fred"},620 Redacted: []string{"password"},621 },622 }, {623 Result: &params.CloudCredential{624 AuthType: "userpass",625 Attributes: map[string]string{"username": "mary"},626 Redacted: []string{"password"},627 },628 },629 })630 c.Assert(s.called, jc.IsTrue)631}632func (s *cloudSuite) createVersionedAddCloudCall(c *gc.C, v int, expectedArg params.AddCloudArgs) basetesting.BestVersionCaller {633 return basetesting.BestVersionCaller{634 APICallerFunc: basetesting.APICallerFunc(635 func(objType string,636 version int,637 id, request string,638 a, result interface{},639 ) error {640 c.Check(objType, gc.Equals, "Cloud")641 c.Check(id, gc.Equals, "")642 c.Check(request, gc.Equals, "AddCloud")643 c.Check(a, jc.DeepEquals, expectedArg)644 s.called = true645 return nil646 },647 ),648 BestVersion: v,649 }650}651var testCloud = cloud.Cloud{652 Name: "foo",653 Type: "dummy",654 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},655 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},656}657func (s *cloudSuite) TestAddCloudNotInV1API(c *gc.C) {658 apiCaller := s.createVersionedAddCloudCall(c, 1, params.AddCloudArgs{})659 client := cloudapi.NewClient(apiCaller)660 err := client.AddCloud(testCloud, false)661 c.Assert(err, gc.ErrorMatches, "AddCloud\\(\\).* not implemented")662 c.Assert(s.called, jc.IsFalse)663}664func (s *cloudSuite) TestAddCloudV2API(c *gc.C) {665 apiCaller := s.createVersionedAddCloudCall(c, 2, params.AddCloudArgs{666 Name: "foo",667 Cloud: common.CloudToParams(testCloud),668 })669 client := cloudapi.NewClient(apiCaller)670 err := client.AddCloud(testCloud, false)671 c.Assert(err, jc.ErrorIsNil)672 c.Assert(s.called, jc.IsTrue)673}674func (s *cloudSuite) TestAddCloudForceNotInVPriorTo6(c *gc.C) {675 apiCaller := s.createVersionedAddCloudCall(c, 5, params.AddCloudArgs{})676 client := cloudapi.NewClient(apiCaller)677 err := client.AddCloud(testCloud, true)678 c.Assert(err, gc.ErrorMatches, "AddCloud\\(\\).* not implemented")679 c.Assert(s.called, jc.IsFalse)680}681func (s *cloudSuite) TestAddCloudForceFromV6(c *gc.C) {682 force := true683 apiCaller := s.createVersionedAddCloudCall(c, 6, params.AddCloudArgs{684 Name: "foo",685 Cloud: common.CloudToParams(testCloud),686 Force: &force,687 })688 client := cloudapi.NewClient(apiCaller)689 err := client.AddCloud(testCloud, force)690 c.Assert(err, jc.ErrorIsNil)691 c.Assert(s.called, jc.IsTrue)692}693func (s *cloudSuite) TestUpdateCloud(c *gc.C) {694 updatedCloud := cloud.Cloud{695 Name: "foo",696 Type: "dummy",697 AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},698 Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}},699 }700 apiCaller := basetesting.BestVersionCaller{701 APICallerFunc: basetesting.APICallerFunc(702 func(objType string,703 version int,704 id, request string,705 a, result interface{},706 ) error {707 s.called = true708 c.Check(objType, gc.Equals, "Cloud")709 c.Check(id, gc.Equals, "")710 c.Check(request, gc.Equals, "UpdateCloud")711 c.Assert(a, jc.DeepEquals, params.UpdateCloudArgs{Clouds: []params.AddCloudArgs{{712 Name: "foo",713 Cloud: common.CloudToParams(updatedCloud),714 }}})715 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})716 *result.(*params.ErrorResults) = params.ErrorResults{717 Results: []params.ErrorResult{{}},718 }719 return nil720 },721 ),722 BestVersion: 4,723 }724 client := cloudapi.NewClient(apiCaller)725 err := client.UpdateCloud(updatedCloud)726 c.Assert(err, jc.ErrorIsNil)727 c.Assert(s.called, jc.IsTrue)728}729func (s *cloudSuite) TestAddCredentialNotInV1API(c *gc.C) {730 apiCaller := basetesting.BestVersionCaller{731 APICallerFunc: basetesting.APICallerFunc(732 func(objType string,733 version int,734 id, request string,735 a, result interface{},736 ) error {737 s.called = true738 return nil739 },740 ),741 BestVersion: 1,742 }743 client := cloudapi.NewClient(apiCaller)744 err := client.AddCredential("cloudcred-acloud-user-credname",745 cloud.NewCredential(cloud.UserPassAuthType, map[string]string{}))746 c.Assert(s.called, jc.IsFalse)747 c.Assert(err, gc.ErrorMatches, "AddCredential\\(\\).* not implemented")748}749func (s *cloudSuite) TestAddCredentialV2API(c *gc.C) {750 apiCaller := basetesting.BestVersionCaller{751 APICallerFunc: basetesting.APICallerFunc(752 func(objType string,753 version int,754 id, request string,755 a, result interface{},756 ) error {757 s.called = true758 c.Check(objType, gc.Equals, "Cloud")759 c.Check(id, gc.Equals, "")760 c.Check(request, gc.Equals, "AddCredentials")761 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})762 *result.(*params.ErrorResults) = params.ErrorResults{763 Results: []params.ErrorResult{{}},764 }765 return nil766 },767 ),768 BestVersion: 2,769 }770 client := cloudapi.NewClient(apiCaller)771 err := client.AddCredential("cloudcred-acloud-user-credname",772 cloud.NewCredential(cloud.UserPassAuthType,773 map[string]string{}))774 c.Assert(err, jc.ErrorIsNil)775 c.Assert(s.called, jc.IsTrue)776}777func (s *cloudSuite) TestCredentialContentsArgumentCheck(c *gc.C) {778 apiCaller := basetesting.BestVersionCaller{BestVersion: 2}779 client := cloudapi.NewClient(apiCaller)780 // Check supplying cloud name without credential name is invalid.781 result, err := client.CredentialContents("cloud", "", true)782 c.Assert(result, gc.IsNil)783 c.Assert(err, gc.ErrorMatches, "credential name must be supplied")784 // Check supplying credential name without cloud name is invalid.785 result, err = client.CredentialContents("", "credential", true)786 c.Assert(result, gc.IsNil)787 c.Assert(err, gc.ErrorMatches, "cloud name must be supplied")788}789func (s *cloudSuite) TestCredentialContentsAll(c *gc.C) {790 expectedResults := []params.CredentialContentResult{791 {792 Result: &params.ControllerCredentialInfo{793 Content: params.CredentialContent{794 Cloud: "cloud-name",795 Name: "credential-name",796 AuthType: "userpass",797 Attributes: map[string]string{798 "username": "fred",799 "password": "sekret"},800 },801 Models: []params.ModelAccess{802 {Model: "abcmodel", Access: "admin"},803 {Model: "xyzmodel", Access: "read"},804 {Model: "no-access-model"}, // no access805 },806 },807 }, {808 Error: apiservererrors.ServerError(errors.New("boom")),809 },810 }811 apiCaller := basetesting.BestVersionCaller{812 APICallerFunc: basetesting.APICallerFunc(813 func(objType string,814 version int,815 id, request string,816 a, result interface{},817 ) error {818 c.Check(objType, gc.Equals, "Cloud")819 c.Check(id, gc.Equals, "")820 c.Check(request, gc.Equals, "CredentialContents")821 c.Assert(result, gc.FitsTypeOf, &params.CredentialContentResults{})822 c.Assert(a, jc.DeepEquals, params.CloudCredentialArgs{823 IncludeSecrets: true,824 })825 *result.(*params.CredentialContentResults) = params.CredentialContentResults{826 Results: expectedResults,827 }828 s.called = true829 return nil830 },831 ),832 BestVersion: 2,833 }834 client := cloudapi.NewClient(apiCaller)835 results, err := client.CredentialContents("", "", true)836 c.Assert(err, jc.ErrorIsNil)837 c.Assert(results, jc.DeepEquals, expectedResults)838 c.Assert(s.called, jc.IsTrue)839}840func (s *cloudSuite) TestCredentialContentsOne(c *gc.C) {841 apiCaller := basetesting.BestVersionCaller{842 APICallerFunc: basetesting.APICallerFunc(843 func(objType string,844 version int,845 id, request string,846 a, result interface{},847 ) error {848 c.Check(objType, gc.Equals, "Cloud")849 c.Check(id, gc.Equals, "")850 c.Check(request, gc.Equals, "CredentialContents")851 c.Assert(result, gc.FitsTypeOf, &params.CredentialContentResults{})852 c.Assert(a, jc.DeepEquals, params.CloudCredentialArgs{853 IncludeSecrets: true,854 Credentials: []params.CloudCredentialArg{855 {CloudName: "cloud-name", CredentialName: "credential-name"},856 },857 })858 *result.(*params.CredentialContentResults) = params.CredentialContentResults{859 Results: []params.CredentialContentResult{860 {},861 },862 }863 s.called = true864 return nil865 },866 ),867 BestVersion: 2,868 }869 client := cloudapi.NewClient(apiCaller)870 results, err := client.CredentialContents("cloud-name", "credential-name", true)871 c.Assert(err, jc.ErrorIsNil)872 c.Assert(results, gc.HasLen, 1)873 c.Assert(s.called, jc.IsTrue)874}875func (s *cloudSuite) TestCredentialContentsGotMoreThanBargainedFor(c *gc.C) {876 apiCaller := basetesting.BestVersionCaller{877 APICallerFunc: basetesting.APICallerFunc(878 func(objType string,879 version int,880 id, request string,881 a, result interface{},882 ) error {883 *result.(*params.CredentialContentResults) = params.CredentialContentResults{884 Results: []params.CredentialContentResult{885 {},886 {},887 },888 }889 s.called = true890 return nil891 },892 ),893 BestVersion: 2,894 }895 client := cloudapi.NewClient(apiCaller)896 results, err := client.CredentialContents("cloud-name", "credential-name", true)897 c.Assert(results, gc.IsNil)898 c.Assert(err, gc.ErrorMatches, "expected 1 result for credential \"cloud-name\" on cloud \"credential-name\", got 2")899 c.Assert(s.called, jc.IsTrue)900}901func (s *cloudSuite) TestCredentialContentsServerError(c *gc.C) {902 apiCaller := basetesting.BestVersionCaller{903 APICallerFunc: basetesting.APICallerFunc(904 func(objType string,905 version int,906 id, request string,907 a, result interface{},908 ) error {909 s.called = true910 return errors.New("boom")911 }),912 BestVersion: 2,913 }914 client := cloudapi.NewClient(apiCaller)915 results, err := client.CredentialContents("", "", true)916 c.Assert(results, gc.IsNil)917 c.Assert(err, gc.ErrorMatches, "boom")918 c.Assert(s.called, jc.IsTrue)919}920func (s *cloudSuite) TestCredentialContentsNotInV2API(c *gc.C) {921 apiCaller := basetesting.BestVersionCaller{922 APICallerFunc: basetesting.APICallerFunc(923 func(objType string,924 version int,925 id, request string,926 a, result interface{},927 ) error {928 s.called = true929 return nil930 },931 ),932 BestVersion: 1,933 }934 client := cloudapi.NewClient(apiCaller)935 _, err := client.CredentialContents("", "", true)936 c.Assert(err, gc.ErrorMatches, "CredentialContents\\(\\).* not implemented")937 c.Assert(s.called, jc.IsFalse)938}939func (s *cloudSuite) TestRemoveCloud(c *gc.C) {940 apiCaller := basetesting.BestVersionCaller{941 APICallerFunc: basetesting.APICallerFunc(942 func(objType string,943 version int,944 id, request string,945 a, result interface{},946 ) error {947 s.called = true948 c.Check(objType, gc.Equals, "Cloud")949 c.Check(id, gc.Equals, "")950 c.Check(request, gc.Equals, "RemoveClouds")951 c.Check(a, jc.DeepEquals, params.Entities{952 Entities: []params.Entity{{Tag: "cloud-foo"}},953 })954 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})955 results := result.(*params.ErrorResults)956 results.Results = append(results.Results, params.ErrorResult{957 Error: &params.Error{Message: "FAIL"},958 })959 return nil960 },961 ),962 BestVersion: 2,963 }964 client := cloudapi.NewClient(apiCaller)965 err := client.RemoveCloud("foo")966 c.Assert(err, gc.ErrorMatches, "FAIL")967 c.Assert(s.called, jc.IsTrue)968}969func (s *cloudSuite) TestRemoveCloudNotInV1API(c *gc.C) {970 apiCaller := basetesting.BestVersionCaller{971 APICallerFunc: basetesting.APICallerFunc(972 func(objType string,973 version int,974 id, request string,975 a, result interface{},976 ) error {977 c.Check(objType, gc.Equals, "Cloud")978 c.Check(id, gc.Equals, "")979 c.Check(request, gc.Equals, "RemoveCloud")980 s.called = true981 return nil982 },983 ),984 BestVersion: 1,985 }986 client := cloudapi.NewClient(apiCaller)987 err := client.RemoveCloud("foo")988 c.Assert(s.called, jc.IsFalse)989 c.Assert(err, gc.ErrorMatches, "RemoveCloud\\(\\).* not implemented")990}991func (s *cloudSuite) TestGrantCloud(c *gc.C) {992 apiCaller := basetesting.BestVersionCaller{993 APICallerFunc: basetesting.APICallerFunc(994 func(objType string,995 version int,996 id, request string,997 a, result interface{},998 ) error {999 s.called = true1000 c.Check(objType, gc.Equals, "Cloud")1001 c.Check(id, gc.Equals, "")1002 c.Check(request, gc.Equals, "ModifyCloudAccess")1003 c.Check(a, jc.DeepEquals, params.ModifyCloudAccessRequest{1004 Changes: []params.ModifyCloudAccess{1005 {UserTag: "user-fred", CloudTag: "cloud-fluffy", Action: "grant", Access: "admin"},1006 },1007 })1008 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})1009 results := result.(*params.ErrorResults)1010 results.Results = append(results.Results, params.ErrorResult{1011 Error: &params.Error{Message: "FAIL"},1012 })1013 return nil1014 },1015 ),1016 BestVersion: 3,1017 }1018 client := cloudapi.NewClient(apiCaller)1019 err := client.GrantCloud("fred", "admin", "fluffy")1020 c.Assert(err, gc.ErrorMatches, "FAIL")1021 c.Assert(s.called, jc.IsTrue)1022}1023func (s *cloudSuite) TestGrantCloudAccessNotInV2API(c *gc.C) {1024 apiCaller := basetesting.BestVersionCaller{1025 APICallerFunc: basetesting.APICallerFunc(1026 func(objType string,1027 version int,1028 id, request string,1029 a, result interface{},1030 ) error {1031 c.Fail()1032 return nil1033 },1034 ),1035 BestVersion: 2,1036 }1037 client := cloudapi.NewClient(apiCaller)1038 err := client.GrantCloud("foo", "admin", "fluffy")1039 c.Assert(err, gc.ErrorMatches, "GrantCloud\\(\\).* not implemented")1040}1041func (s *cloudSuite) TestRevokeCloud(c *gc.C) {1042 apiCaller := basetesting.BestVersionCaller{1043 APICallerFunc: basetesting.APICallerFunc(1044 func(objType string,1045 version int,1046 id, request string,1047 a, result interface{},1048 ) error {1049 s.called = true1050 c.Check(objType, gc.Equals, "Cloud")1051 c.Check(id, gc.Equals, "")1052 c.Check(request, gc.Equals, "ModifyCloudAccess")1053 c.Check(a, jc.DeepEquals, params.ModifyCloudAccessRequest{1054 Changes: []params.ModifyCloudAccess{1055 {UserTag: "user-fred", CloudTag: "cloud-fluffy", Action: "revoke", Access: "admin"},1056 },1057 })1058 c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})1059 results := result.(*params.ErrorResults)1060 results.Results = append(results.Results, params.ErrorResult{1061 Error: &params.Error{Message: "FAIL"},1062 })1063 return nil1064 },1065 ),1066 BestVersion: 3,1067 }1068 client := cloudapi.NewClient(apiCaller)1069 err := client.RevokeCloud("fred", "admin", "fluffy")1070 c.Assert(err, gc.ErrorMatches, "FAIL")1071 c.Assert(s.called, jc.IsTrue)1072}1073func (s *cloudSuite) TestRevokeCloudAccessNotInV2API(c *gc.C) {1074 apiCaller := basetesting.BestVersionCaller{1075 APICallerFunc: basetesting.APICallerFunc(1076 func(objType string,1077 version int,1078 id, request string,1079 a, result interface{},1080 ) error {1081 c.Fail()1082 return nil1083 },1084 ),1085 BestVersion: 2,1086 }1087 client := cloudapi.NewClient(apiCaller)1088 err := client.RevokeCloud("foo", "admin", "fluffy")1089 c.Assert(err, gc.ErrorMatches, "RevokeCloud\\(\\).* not implemented")1090}1091func createCredentials(n int) map[string]cloud.Credential {1092 result := map[string]cloud.Credential{}1093 for i := 0; i < n; i++ {1094 result[names.NewCloudCredentialTag(fmt.Sprintf("foo/bob/bar%d", i)).String()] = testCredential1095 }1096 return result1097}1098func (s *cloudSuite) TestUpdateCloudsCredentials(c *gc.C) {1099 apiCaller := basetesting.BestVersionCaller{1100 APICallerFunc: basetesting.APICallerFunc(1101 func(objType string,1102 version int,1103 id, request string,1104 a, result interface{},1105 ) error {1106 c.Check(objType, gc.Equals, "Cloud")1107 c.Check(id, gc.Equals, "")1108 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1109 c.Assert(result, gc.FitsTypeOf, &params.UpdateCredentialResults{})1110 c.Assert(a, jc.DeepEquals, params.UpdateCredentialArgs{1111 Force: true,1112 Credentials: []params.TaggedCredential{{1113 Tag: "cloudcred-foo_bob_bar0",1114 Credential: params.CloudCredential{1115 AuthType: "userpass",1116 Attributes: map[string]string{1117 "username": "admin",1118 "password": "adm1n",1119 },1120 },1121 }}})1122 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1123 Results: []params.UpdateCredentialResult{{}},1124 }1125 s.called = true1126 return nil1127 },1128 ),1129 BestVersion: 3,1130 }1131 client := cloudapi.NewClient(apiCaller)1132 result, err := client.UpdateCloudsCredentials(createCredentials(1), true)1133 c.Assert(err, jc.ErrorIsNil)1134 c.Assert(result, gc.DeepEquals, []params.UpdateCredentialResult{{}})1135 c.Assert(s.called, jc.IsTrue)1136}1137func (s *cloudSuite) TestUpdateCloudsCredentialsErrorV2(c *gc.C) {1138 apiCaller := basetesting.BestVersionCaller{1139 APICallerFunc: basetesting.APICallerFunc(1140 func(objType string,1141 version int,1142 id, request string,1143 a, result interface{},1144 ) error {1145 c.Check(request, gc.Equals, "UpdateCredentials")1146 *result.(*params.ErrorResults) = params.ErrorResults{1147 Results: []params.ErrorResult{{apiservererrors.ServerError(errors.New("validation failure"))}},1148 }1149 s.called = true1150 return nil1151 },1152 ),1153 BestVersion: 2,1154 }1155 client := cloudapi.NewClient(apiCaller)1156 errs, err := client.UpdateCloudsCredentials(createCredentials(1), true)1157 c.Assert(err, jc.ErrorIsNil)1158 c.Assert(errs, gc.DeepEquals, []params.UpdateCredentialResult{1159 {CredentialTag: "cloudcred-foo_bob_bar0", Error: &params.Error{Message: "validation failure", Code: ""}},1160 })1161 c.Assert(s.called, jc.IsTrue)1162}1163func (s *cloudSuite) TestUpdateCloudsCredentialsError(c *gc.C) {1164 apiCaller := basetesting.BestVersionCaller{1165 APICallerFunc: basetesting.APICallerFunc(1166 func(objType string,1167 version int,1168 id, request string,1169 a, result interface{},1170 ) error {1171 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1172 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1173 Results: []params.UpdateCredentialResult{1174 {CredentialTag: "cloudcred-foo_bob_bar0",1175 Error: apiservererrors.ServerError(errors.New("validation failure")),1176 },1177 },1178 }1179 s.called = true1180 return nil1181 },1182 ),1183 BestVersion: 3,1184 }1185 client := cloudapi.NewClient(apiCaller)1186 errs, err := client.UpdateCloudsCredentials(createCredentials(1), false)1187 c.Assert(err, jc.ErrorIsNil)1188 c.Assert(errs, gc.DeepEquals, []params.UpdateCredentialResult{1189 {CredentialTag: "cloudcred-foo_bob_bar0", Error: apiservererrors.ServerError(errors.New("validation failure"))},1190 })1191 c.Assert(s.called, jc.IsTrue)1192}1193func (s *cloudSuite) TestUpdateCloudsCredentialsMasksLegacyError(c *gc.C) {1194 apiCaller := basetesting.BestVersionCaller{1195 APICallerFunc: basetesting.APICallerFunc(1196 func(objType string,1197 version int,1198 id, request string,1199 a, result interface{},1200 ) error {1201 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1202 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1203 Results: []params.UpdateCredentialResult{1204 {CredentialTag: "cloudcred-foo_bob_bar0",1205 Error: apiservererrors.ServerError(errors.New("some models are no longer visible")),1206 },1207 },1208 }1209 s.called = true1210 return nil1211 },1212 ),1213 BestVersion: 6,1214 }1215 client := cloudapi.NewClient(apiCaller)1216 errs, err := client.UpdateCloudsCredentials(createCredentials(1), false)1217 c.Assert(err, jc.ErrorIsNil)1218 c.Assert(errs, gc.DeepEquals, []params.UpdateCredentialResult{1219 {CredentialTag: "cloudcred-foo_bob_bar0"},1220 })1221 c.Assert(s.called, jc.IsTrue)1222}1223func (s *cloudSuite) TestUpdateCloudsCredentialsCallErrorV2(c *gc.C) {1224 apiCaller := basetesting.BestVersionCaller{1225 APICallerFunc: basetesting.APICallerFunc(1226 func(objType string,1227 version int,1228 id, request string,1229 a, result interface{},1230 ) error {1231 c.Check(request, gc.Equals, "UpdateCredentials")1232 s.called = true1233 return errors.New("scary but true")1234 },1235 ),1236 BestVersion: 2,1237 }1238 client := cloudapi.NewClient(apiCaller)1239 result, err := client.UpdateCloudsCredentials(createCredentials(1), false)1240 c.Assert(err, gc.ErrorMatches, "scary but true")1241 c.Assert(result, gc.IsNil)1242 c.Assert(s.called, jc.IsTrue)1243}1244func (s *cloudSuite) TestUpdateCloudsCredentialsCallError(c *gc.C) {1245 apiCaller := basetesting.BestVersionCaller{1246 APICallerFunc: basetesting.APICallerFunc(1247 func(objType string,1248 version int,1249 id, request string,1250 a, result interface{},1251 ) error {1252 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1253 s.called = true1254 return errors.New("scary but true")1255 },1256 ),1257 BestVersion: 3,1258 }1259 client := cloudapi.NewClient(apiCaller)1260 result, err := client.UpdateCloudsCredentials(createCredentials(1), false)1261 c.Assert(err, gc.ErrorMatches, "scary but true")1262 c.Assert(result, gc.IsNil)1263 c.Assert(s.called, jc.IsTrue)1264}1265func (s *cloudSuite) TestUpdateCloudsCredentialsManyResultsV2(c *gc.C) {1266 apiCaller := basetesting.BestVersionCaller{1267 APICallerFunc: basetesting.APICallerFunc(1268 func(objType string,1269 version int,1270 id, request string,1271 a, result interface{},1272 ) error {1273 c.Check(request, gc.Equals, "UpdateCredentials")1274 *result.(*params.ErrorResults) = params.ErrorResults{1275 Results: []params.ErrorResult{1276 {},1277 {},1278 },1279 }1280 s.called = true1281 return nil1282 },1283 ),1284 BestVersion: 2,1285 }1286 client := cloudapi.NewClient(apiCaller)1287 result, err := client.UpdateCloudsCredentials(createCredentials(1), false)1288 c.Assert(err, gc.ErrorMatches, `expected 1 result got 2 when updating credentials`)1289 c.Assert(result, gc.IsNil)1290 c.Assert(s.called, jc.IsTrue)1291}1292func (s *cloudSuite) TestUpdateCloudsCredentialsManyMatchingResultsV2(c *gc.C) {1293 apiCaller := basetesting.BestVersionCaller{1294 APICallerFunc: basetesting.APICallerFunc(1295 func(objType string,1296 version int,1297 id, request string,1298 a, result interface{},1299 ) error {1300 c.Check(request, gc.Equals, "UpdateCredentials")1301 *result.(*params.ErrorResults) = params.ErrorResults{1302 Results: []params.ErrorResult{1303 {},1304 {},1305 },1306 }1307 s.called = true1308 return nil1309 },1310 ),1311 BestVersion: 2,1312 }1313 client := cloudapi.NewClient(apiCaller)1314 in := createCredentials(2)1315 result, err := client.UpdateCloudsCredentials(in, false)1316 c.Assert(err, jc.ErrorIsNil)1317 c.Assert(result, gc.HasLen, len(in))1318 for _, one := range result {1319 _, ok := in[one.CredentialTag]1320 c.Assert(ok, jc.IsTrue)1321 }1322 c.Assert(s.called, jc.IsTrue)1323}1324func (s *cloudSuite) TestUpdateCloudsCredentialsManyResults(c *gc.C) {1325 apiCaller := basetesting.BestVersionCaller{1326 APICallerFunc: basetesting.APICallerFunc(1327 func(objType string,1328 version int,1329 id, request string,1330 a, result interface{},1331 ) error {1332 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1333 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1334 Results: []params.UpdateCredentialResult{1335 {},1336 {},1337 }}1338 s.called = true1339 return nil1340 },1341 ),1342 BestVersion: 3,1343 }1344 client := cloudapi.NewClient(apiCaller)1345 result, err := client.UpdateCloudsCredentials(createCredentials(1), false)1346 c.Assert(err, gc.ErrorMatches, `expected 1 result got 2 when updating credentials`)1347 c.Assert(result, gc.IsNil)1348 c.Assert(s.called, jc.IsTrue)1349}1350func (s *cloudSuite) TestUpdateCloudsCredentialsManyMatchingResults(c *gc.C) {1351 apiCaller := basetesting.BestVersionCaller{1352 APICallerFunc: basetesting.APICallerFunc(1353 func(objType string,1354 version int,1355 id, request string,1356 a, result interface{},1357 ) error {1358 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1359 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1360 Results: []params.UpdateCredentialResult{1361 {},1362 {},1363 }}1364 s.called = true1365 return nil1366 },1367 ),1368 BestVersion: 3,1369 }1370 client := cloudapi.NewClient(apiCaller)1371 count := 21372 result, err := client.UpdateCloudsCredentials(createCredentials(count), false)1373 c.Assert(err, jc.ErrorIsNil)1374 c.Assert(result, gc.HasLen, count)1375 c.Assert(s.called, jc.IsTrue)1376}1377func (s *cloudSuite) TestUpdateCloudsCredentialsModelErrors(c *gc.C) {1378 apiCaller := basetesting.BestVersionCaller{1379 APICallerFunc: basetesting.APICallerFunc(1380 func(objType string,1381 version int,1382 id, request string,1383 a, result interface{},1384 ) error {1385 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1386 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1387 Results: []params.UpdateCredentialResult{1388 {1389 CredentialTag: testCredentialTag.String(),1390 Models: []params.UpdateCredentialModelResult{1391 {1392 ModelUUID: coretesting.ModelTag.Id(),1393 ModelName: "test-model",1394 Errors: []params.ErrorResult{1395 {apiservererrors.ServerError(errors.New("validation failure one"))},1396 {apiservererrors.ServerError(errors.New("validation failure two"))},1397 },1398 },1399 },1400 },1401 }}1402 s.called = true1403 return nil1404 },1405 ),1406 BestVersion: 3,1407 }1408 client := cloudapi.NewClient(apiCaller)1409 errs, err := client.UpdateCloudsCredentials(createCredentials(1), false)1410 c.Assert(err, jc.ErrorIsNil)1411 c.Assert(errs, gc.DeepEquals, []params.UpdateCredentialResult{1412 {CredentialTag: "cloudcred-foo_bob_bar",1413 Models: []params.UpdateCredentialModelResult{1414 {ModelUUID: "deadbeef-0bad-400d-8000-4b1d0d06f00d",1415 ModelName: "test-model",1416 Errors: []params.ErrorResult{1417 {apiservererrors.ServerError(errors.New("validation failure one"))},1418 {apiservererrors.ServerError(errors.New("validation failure two"))},1419 },1420 },1421 },1422 },1423 })1424 c.Assert(s.called, jc.IsTrue)1425}1426func (s *cloudSuite) TestAddCloudsCredentials(c *gc.C) {1427 apiCaller := basetesting.BestVersionCaller{1428 APICallerFunc: basetesting.APICallerFunc(1429 func(objType string,1430 version int,1431 id, request string,1432 a, result interface{},1433 ) error {1434 c.Check(objType, gc.Equals, "Cloud")1435 c.Check(id, gc.Equals, "")1436 c.Check(request, gc.Equals, "UpdateCredentialsCheckModels")1437 c.Assert(result, gc.FitsTypeOf, &params.UpdateCredentialResults{})1438 c.Assert(a, jc.DeepEquals, params.UpdateCredentialArgs{1439 Credentials: []params.TaggedCredential{{1440 Tag: "cloudcred-foo_bob_bar0",1441 Credential: params.CloudCredential{1442 AuthType: "userpass",1443 Attributes: map[string]string{1444 "username": "admin",1445 "password": "adm1n",1446 },1447 },1448 }}})1449 *result.(*params.UpdateCredentialResults) = params.UpdateCredentialResults{1450 Results: []params.UpdateCredentialResult{{}},1451 }1452 s.called = true1453 return nil1454 },1455 ),1456 BestVersion: 3,1457 }1458 client := cloudapi.NewClient(apiCaller)1459 result, err := client.AddCloudsCredentials(createCredentials(1))1460 c.Assert(err, jc.ErrorIsNil)1461 c.Assert(result, gc.DeepEquals, []params.UpdateCredentialResult{{}})1462 c.Assert(s.called, jc.IsTrue)1463}...

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 sess := session.New()4 service := services.GetVirtualGuestService(sess)5 vms, err := service.Mask("id;hostname;domain").Limit(5).GetAllObjects()6 if err != nil {7 fmt.Printf("Error getting virtual guests: %s8 }9 for _, vm := range vms {10 fmt.Printf("%d %s.%s11 }12}13import (14func main() {15 sess := session.New()16 service := services.GetVirtualGuestService(sess)17 vms, err := service.Mask("id;hostname;domain").Limit(5).GetAllObjects()18 if err != nil {19 fmt.Printf("Error getting virtual guests: %s20 }21 for _, vm := range vms {22 fmt.Printf("%d %s.%s23 }24}25import (26func main() {27 sess := session.New()28 service := services.GetVirtualGuestService(sess)

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1type Client struct {2}3func NewClient() *Client {4 return &Client{}5}6func (c *Client) ListImages() {7}8import (9func main() {10 c := cloudapi.NewClient()11 c.ListImages()12}13import (14func main() {15 c := cloudapi.NewClient()16 c.ListImages()17}18import (19func main() {20 c := cloudapi.NewClient()21 c.ListImages()22}

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 svc := cloudwatch.New(aws.NewConfig().WithRegion("us-west-2"))4 params := &cloudwatch.DescribeAlarmsInput{5 AlarmNames: []string{6 },7 }8 resp, err := svc.DescribeAlarms(params)9 if err != nil {10 fmt.Println("Error", err)11 } else {12 fmt.Println("Success", resp)13 }14}15Success &{AlarmDescriptions:[{AlarmARN:arn:aws:cloudwatch:us-west-2:123456789012:alarm:my-alarm AlarmConfigurationUpdatedTimestamp:2014-12-04T15:42:28Z AlarmDescription: AlarmName:my-alarm ComparisonOperator:GreaterThanOrEqualToThreshold EvaluationPeriods:1 InsufficientDataActions:[] MetricName:CPUUtilization Namespace:AWS/EC2 OKActions:[] Period:60 StateReason:Threshold Crossed: 1 datapoint [1.0 (12/04/14 15:42:00)] was greater than or equal to the threshold (1.0) StateReasonData:{"version":"1.0","queryDate":"2014-12-04T15:42:00.000-08:00","statistic":"Average","period":60,"recentDatapoints":[1.0],"threshold":1.0,"trigger":{"MetricName":"CPUUtilization","Namespace":"AWS/EC2","Statistic":"Average","Unit":null,"Dimensions":[{"Name":"InstanceId","Value":"i-12345678"}]},"region":"us-west-2"} StateUpdatedTimestamp:2014-12-04T15:42:28Z StateValue:OK ThresholdMetricID: Dimensions:[{Name:InstanceId Value:i-12345678}] Statistic:Average Threshold:1.0 TreatMissingData: TreatMissingData:breaching Unit:}] MetricAlarms:[] NextToken:}

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client, err := cloudapi.NewClient(cloudapi.ClientConfig{4 })5 if err != nil {6 panic(err)7 }8 fmt.Println(client)9}10import (11func main() {12 client, err := cloudapi.NewClient(cloudapi.ClientConfig{13 })14 if err != nil {15 panic(err)16 }17 fmt.Println(client)18}19import (20func main() {21 client, err := cloudapi.NewClient(cloudapi.ClientConfig{22 })23 if err != nil {24 panic(err)25 }26 fmt.Println(client)27}28import (29func main() {30 client, err := cloudapi.NewClient(cloudapi.ClientConfig{31 })32 if err != nil {33 panic(err)34 }35 fmt.Println(client)36}37import (38func main() {39 client, err := cloudapi.NewClient(cloudapi.ClientConfig{

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 packages, err := client.GetPackages()7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println(packages)11}

Full Screen

Full Screen

NewClient

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15}16import (17func main() {18}19import (20func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful