github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/provider/oci/common/ociclients_test.go (about) 1 // Copyright 2021 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 ctx "context" 8 9 "github.com/juju/errors" 10 jc "github.com/juju/testing/checkers" 11 ociCommon "github.com/oracle/oci-go-sdk/v65/common" 12 ociCore "github.com/oracle/oci-go-sdk/v65/core" 13 "go.uber.org/mock/gomock" 14 gc "gopkg.in/check.v1" 15 16 "github.com/juju/juju/environs/tags" 17 "github.com/juju/juju/provider/oci/testing" 18 ) 19 20 var _ = gc.Suite(&computeClientSuite{}) 21 var _ = gc.Suite(&networkClientSuite{}) 22 var _ = gc.Suite(&storageClientSuite{}) 23 24 var compartmentID = "compartment-id" 25 26 func makeStringPointer(name string) *string { 27 return &name 28 } 29 30 func makeIntPointer(name int) *int { 31 return &name 32 } 33 34 type computeClientSuite struct { 35 client *computeClient 36 mockAPI *testing.MockOCIComputeClient 37 images []ociCore.Image 38 instances []ociCore.Instance 39 vnics []ociCore.VnicAttachment 40 volumes []ociCore.VolumeAttachment 41 } 42 43 func (s *computeClientSuite) SetUpSuite(c *gc.C) { 44 s.images = []ociCore.Image{ 45 { 46 CompartmentId: &compartmentID, 47 Id: makeStringPointer("fakeUbuntu1"), 48 OperatingSystem: makeStringPointer("Canonical Ubuntu"), 49 OperatingSystemVersion: makeStringPointer("22.04"), 50 DisplayName: makeStringPointer("Canonical-Ubuntu-22.04-2018.01.11-0"), 51 }, 52 { 53 CompartmentId: &compartmentID, 54 Id: makeStringPointer("fakeUbuntu2"), 55 OperatingSystem: makeStringPointer("Canonical Ubuntu"), 56 OperatingSystemVersion: makeStringPointer("22.04"), 57 DisplayName: makeStringPointer("Canonical-Ubuntu-22.04-2018.01.12-0"), 58 }, 59 { 60 CompartmentId: &compartmentID, 61 Id: makeStringPointer("fakeCentOS"), 62 OperatingSystem: makeStringPointer("CentOS"), 63 OperatingSystemVersion: makeStringPointer("7"), 64 DisplayName: makeStringPointer("CentOS-7-2017.10.19-0"), 65 }, 66 } 67 68 s.instances = []ociCore.Instance{ 69 { 70 AvailabilityDomain: makeStringPointer("fakeZone1"), 71 CompartmentId: &compartmentID, 72 Id: makeStringPointer("instID"), 73 LifecycleState: ociCore.InstanceLifecycleStateRunning, 74 Region: makeStringPointer("us-phoenix-1"), 75 Shape: makeStringPointer("VM.Standard1.1"), 76 DisplayName: makeStringPointer("fakeName"), 77 }, 78 { 79 AvailabilityDomain: makeStringPointer("fakeZone2"), 80 CompartmentId: &compartmentID, 81 Id: makeStringPointer("instID3"), 82 LifecycleState: ociCore.InstanceLifecycleStateRunning, 83 Region: makeStringPointer("us-phoenix-1"), 84 Shape: makeStringPointer("VM.Standard2.1"), 85 DisplayName: makeStringPointer("fakeNameTheSecond"), 86 }, 87 } 88 89 fakeInstID := "fakeInstanceId" 90 s.vnics = []ociCore.VnicAttachment{ 91 { 92 Id: makeStringPointer("fakeAttachmentId"), 93 AvailabilityDomain: makeStringPointer("fake"), 94 CompartmentId: &compartmentID, 95 InstanceId: &fakeInstID, 96 LifecycleState: ociCore.VnicAttachmentLifecycleStateAttached, 97 DisplayName: makeStringPointer("fakeAttachmentName"), 98 NicIndex: makeIntPointer(0), 99 VnicId: makeStringPointer("vnicID1"), 100 }, 101 { 102 Id: makeStringPointer("fakeAttachmentId2"), 103 AvailabilityDomain: makeStringPointer("fake2"), 104 CompartmentId: &compartmentID, 105 InstanceId: &fakeInstID, 106 LifecycleState: ociCore.VnicAttachmentLifecycleStateAttached, 107 DisplayName: makeStringPointer("fakeAttachmentName2"), 108 NicIndex: makeIntPointer(1), 109 VnicId: makeStringPointer("vnicID2"), 110 }, 111 } 112 113 s.volumes = []ociCore.VolumeAttachment{ 114 ociCore.IScsiVolumeAttachment{ 115 AvailabilityDomain: makeStringPointer("fakeZone1"), 116 InstanceId: &fakeInstID, 117 CompartmentId: &compartmentID, 118 Iqn: makeStringPointer("bogus"), 119 Id: makeStringPointer("fakeVolumeAttachment1"), 120 VolumeId: makeStringPointer("volume1"), 121 Ipv4: makeStringPointer("192.168.1.1"), 122 DisplayName: makeStringPointer("fakeVolumeAttachment"), 123 ChapSecret: makeStringPointer("superSecretPassword"), 124 ChapUsername: makeStringPointer("JohnDoe"), 125 LifecycleState: ociCore.VolumeAttachmentLifecycleStateAttached, 126 }, 127 ociCore.IScsiVolumeAttachment{ 128 AvailabilityDomain: makeStringPointer("fakeZone1"), 129 InstanceId: &fakeInstID, 130 CompartmentId: &compartmentID, 131 Iqn: makeStringPointer("bogus"), 132 Id: makeStringPointer("fakeVolumeAttachment2"), 133 VolumeId: makeStringPointer("volume2"), 134 Ipv4: makeStringPointer("192.168.1.42"), 135 DisplayName: makeStringPointer("fakeVolumeAttachment"), 136 ChapSecret: makeStringPointer("superSecretPassword"), 137 ChapUsername: makeStringPointer("JohnDoe"), 138 LifecycleState: ociCore.VolumeAttachmentLifecycleStateAttached, 139 }, 140 } 141 } 142 143 func (s *computeClientSuite) TestListImages(c *gc.C) { 144 ctrl := s.setupMocks(c) 145 defer ctrl.Finish() 146 147 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{ 148 Items: s.images, 149 }, nil) 150 151 obtained, err := s.client.ListImages(ctx.TODO(), &compartmentID) 152 c.Assert(err, jc.ErrorIsNil) 153 c.Assert(obtained, gc.DeepEquals, s.images) 154 } 155 156 func (s *computeClientSuite) TestListImagesPageN(c *gc.C) { 157 ctrl := s.setupMocks(c) 158 defer ctrl.Finish() 159 160 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{ 161 Items: []ociCore.Image{s.images[0]}, 162 OpcNextPage: makeStringPointer("test-pagination"), 163 }, nil) 164 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{ 165 Items: []ociCore.Image{s.images[1]}, 166 OpcNextPage: makeStringPointer("test-pagination"), 167 }, nil) 168 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{ 169 Items: []ociCore.Image{s.images[2]}, 170 }, nil) 171 172 obtained, err := s.client.ListImages(ctx.TODO(), &compartmentID) 173 c.Assert(err, jc.ErrorIsNil) 174 c.Assert(obtained, gc.DeepEquals, s.images) 175 } 176 177 func (s *computeClientSuite) TestListImagesFail(c *gc.C) { 178 ctrl := s.setupMocks(c) 179 defer ctrl.Finish() 180 181 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{}, errors.BadRequestf("test fail")) 182 183 obtained, err := s.client.ListImages(ctx.TODO(), &compartmentID) 184 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 185 c.Assert(obtained, gc.HasLen, 0) 186 } 187 188 func (s *computeClientSuite) TestListImagesFailPageN(c *gc.C) { 189 ctrl := s.setupMocks(c) 190 defer ctrl.Finish() 191 192 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{ 193 Items: []ociCore.Image{s.images[0]}, 194 OpcNextPage: makeStringPointer("test-pagination"), 195 }, nil) 196 s.mockAPI.EXPECT().ListImages(gomock.Any(), gomock.Any()).Return(ociCore.ListImagesResponse{}, errors.BadRequestf("test fail")) 197 198 obtained, err := s.client.ListImages(ctx.TODO(), &compartmentID) 199 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 200 c.Assert(obtained, gc.HasLen, 0) 201 } 202 203 func (s *computeClientSuite) TestListShapes(c *gc.C) { 204 ctrl := s.setupMocks(c) 205 defer ctrl.Finish() 206 207 shape1 := "VM.Standard2.1" 208 shape2 := "VM.Standard1.2" 209 req := ociCore.ListShapesRequest{ 210 CompartmentId: &compartmentID, 211 AvailabilityDomain: nil, 212 Limit: nil, 213 Page: nil, 214 ImageId: s.images[1].Id, 215 OpcRequestId: nil, 216 RequestMetadata: ociCommon.RequestMetadata{}, 217 } 218 resp := ociCore.ListShapesResponse{ 219 Items: []ociCore.Shape{ 220 {Shape: &shape1}, 221 {Shape: &shape2}, 222 }, 223 } 224 s.mockAPI.EXPECT().ListShapes(gomock.Any(), req).Return(resp, nil) 225 226 obtained, err := s.client.ListShapes(ctx.TODO(), &compartmentID, s.images[1].Id) 227 c.Assert(err, jc.ErrorIsNil) 228 c.Assert(obtained, gc.HasLen, 2) 229 c.Assert(obtained[0].Shape, gc.Equals, &shape1) 230 c.Assert(obtained[1].Shape, gc.Equals, &shape2) 231 } 232 233 func (s *computeClientSuite) TestListShapesPageN(c *gc.C) { 234 ctrl := s.setupMocks(c) 235 defer ctrl.Finish() 236 237 shape1 := "VM.Standard2.1" 238 shape2 := "VM.Standard1.2" 239 req := ociCore.ListShapesRequest{ 240 CompartmentId: &compartmentID, 241 ImageId: s.images[1].Id, 242 } 243 shapes := []ociCore.Shape{ 244 {Shape: &shape1}, 245 {Shape: &shape2}, 246 } 247 resp := ociCore.ListShapesResponse{ 248 Items: []ociCore.Shape{shapes[0]}, 249 OpcNextPage: makeStringPointer("test-pagination"), 250 } 251 252 s.mockAPI.EXPECT().ListShapes(gomock.Any(), req).Return(resp, nil) 253 req.Page = resp.OpcNextPage 254 s.mockAPI.EXPECT().ListShapes(gomock.Any(), req).Return(ociCore.ListShapesResponse{ 255 Items: []ociCore.Shape{shapes[1]}, 256 }, nil) 257 258 obtained, err := s.client.ListShapes(ctx.TODO(), &compartmentID, req.ImageId) 259 c.Assert(err, jc.ErrorIsNil) 260 c.Assert(obtained, gc.HasLen, 2) 261 c.Assert(obtained[0].Shape, gc.Equals, &shape1) 262 c.Assert(obtained[1].Shape, gc.Equals, &shape2) 263 } 264 265 func (s *computeClientSuite) TestListShapesFail(c *gc.C) { 266 ctrl := s.setupMocks(c) 267 defer ctrl.Finish() 268 269 s.mockAPI.EXPECT().ListShapes(gomock.Any(), gomock.Any()).Return(ociCore.ListShapesResponse{}, errors.BadRequestf("test fail")) 270 271 obtained, err := s.client.ListShapes(ctx.TODO(), &compartmentID, makeStringPointer("testFail")) 272 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 273 c.Assert(obtained, gc.HasLen, 0) 274 } 275 276 func (s *computeClientSuite) TestListShapesFailPageN(c *gc.C) { 277 ctrl := s.setupMocks(c) 278 defer ctrl.Finish() 279 280 shape1 := "VM.Standard2.1" 281 282 req := ociCore.ListShapesRequest{ 283 CompartmentId: &compartmentID, 284 ImageId: makeStringPointer("testFail"), 285 } 286 shapes := []ociCore.Shape{ 287 {Shape: &shape1}, 288 } 289 resp := ociCore.ListShapesResponse{ 290 Items: shapes, 291 OpcNextPage: makeStringPointer("test-pagination"), 292 } 293 s.mockAPI.EXPECT().ListShapes(gomock.Any(), req).Return(resp, nil) 294 req.Page = resp.OpcNextPage 295 s.mockAPI.EXPECT().ListShapes(gomock.Any(), req).Return( 296 ociCore.ListShapesResponse{}, errors.BadRequestf("test fail")) 297 298 obtained, err := s.client.ListShapes(ctx.TODO(), &compartmentID, req.ImageId) 299 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 300 c.Assert(obtained, gc.HasLen, 0) 301 } 302 303 func (s *computeClientSuite) TestListInstances(c *gc.C) { 304 ctrl := s.setupMocks(c) 305 defer ctrl.Finish() 306 307 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{ 308 Items: s.instances, 309 }, nil) 310 311 obtained, err := s.client.ListInstances(ctx.TODO(), &compartmentID) 312 c.Assert(err, jc.ErrorIsNil) 313 c.Assert(obtained, gc.DeepEquals, s.instances) 314 } 315 316 func (s *computeClientSuite) TestListInstancesPageN(c *gc.C) { 317 ctrl := s.setupMocks(c) 318 defer ctrl.Finish() 319 320 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{ 321 Items: []ociCore.Instance{s.instances[0]}, 322 OpcNextPage: makeStringPointer("test-pagination"), 323 }, nil) 324 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{ 325 Items: []ociCore.Instance{s.instances[1]}, 326 }, nil) 327 328 obtained, err := s.client.ListInstances(ctx.TODO(), &compartmentID) 329 c.Assert(err, jc.ErrorIsNil) 330 c.Assert(obtained, gc.DeepEquals, s.instances) 331 } 332 333 func (s *computeClientSuite) TestListInstancesFail(c *gc.C) { 334 ctrl := s.setupMocks(c) 335 defer ctrl.Finish() 336 337 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{}, errors.BadRequestf("test fail")) 338 339 obtained, err := s.client.ListInstances(ctx.TODO(), &compartmentID) 340 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 341 c.Assert(obtained, gc.HasLen, 0) 342 } 343 344 func (s *computeClientSuite) TestListInstancesFailPageN(c *gc.C) { 345 ctrl := s.setupMocks(c) 346 defer ctrl.Finish() 347 348 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{ 349 Items: []ociCore.Instance{s.instances[0]}, 350 OpcNextPage: makeStringPointer("test-pagination"), 351 }, nil) 352 s.mockAPI.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Return(ociCore.ListInstancesResponse{}, errors.BadRequestf("test fail")) 353 354 obtained, err := s.client.ListInstances(ctx.TODO(), &compartmentID) 355 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 356 c.Assert(obtained, gc.HasLen, 0) 357 } 358 359 func (s *computeClientSuite) TestListVnicAttachments(c *gc.C) { 360 ctrl := s.setupMocks(c) 361 defer ctrl.Finish() 362 363 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), gomock.Any()).Return(ociCore.ListVnicAttachmentsResponse{ 364 Items: s.vnics, 365 }, nil) 366 367 obtained, err := s.client.ListVnicAttachments(ctx.TODO(), &compartmentID, s.vnics[0].InstanceId) 368 c.Assert(err, jc.ErrorIsNil) 369 c.Assert(obtained, gc.DeepEquals, s.vnics) 370 } 371 372 func (s *computeClientSuite) TestListVnicAttachmentsPageN(c *gc.C) { 373 ctrl := s.setupMocks(c) 374 defer ctrl.Finish() 375 376 req := ociCore.ListVnicAttachmentsRequest{ 377 CompartmentId: &compartmentID, 378 InstanceId: s.vnics[0].InstanceId, 379 } 380 resp := ociCore.ListVnicAttachmentsResponse{ 381 Items: []ociCore.VnicAttachment{s.vnics[0]}, 382 OpcNextPage: makeStringPointer("test-pagination"), 383 } 384 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), req).Return(resp, nil) 385 req.Page = resp.OpcNextPage 386 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), req).Return( 387 ociCore.ListVnicAttachmentsResponse{ 388 Items: []ociCore.VnicAttachment{s.vnics[1]}, 389 }, nil) 390 391 obtained, err := s.client.ListVnicAttachments(ctx.TODO(), &compartmentID, s.vnics[0].InstanceId) 392 c.Assert(err, jc.ErrorIsNil) 393 c.Assert(obtained, gc.DeepEquals, s.vnics) 394 } 395 396 func (s *computeClientSuite) TestListVnicAttachmentsFail(c *gc.C) { 397 ctrl := s.setupMocks(c) 398 defer ctrl.Finish() 399 400 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), gomock.Any()).Return(ociCore.ListVnicAttachmentsResponse{}, errors.BadRequestf("test fail")) 401 402 obtained, err := s.client.ListVnicAttachments(ctx.TODO(), &compartmentID, s.vnics[0].InstanceId) 403 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 404 c.Assert(obtained, gc.HasLen, 0) 405 } 406 407 func (s *computeClientSuite) TestListVnicAttachmentsFailPageN(c *gc.C) { 408 ctrl := s.setupMocks(c) 409 defer ctrl.Finish() 410 411 req := ociCore.ListVnicAttachmentsRequest{ 412 CompartmentId: &compartmentID, 413 InstanceId: s.vnics[0].InstanceId, 414 } 415 resp := ociCore.ListVnicAttachmentsResponse{ 416 Items: []ociCore.VnicAttachment{s.vnics[0]}, 417 OpcNextPage: makeStringPointer("test-pagination"), 418 } 419 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), req).Return(resp, nil) 420 req.Page = resp.OpcNextPage 421 s.mockAPI.EXPECT().ListVnicAttachments(gomock.Any(), req).Return(ociCore.ListVnicAttachmentsResponse{}, errors.BadRequestf("test fail")) 422 423 obtained, err := s.client.ListVnicAttachments(ctx.TODO(), &compartmentID, s.vnics[0].InstanceId) 424 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 425 c.Assert(obtained, gc.HasLen, 0) 426 } 427 428 func (s *computeClientSuite) TestListVolumeAttachments(c *gc.C) { 429 ctrl := s.setupMocks(c) 430 defer ctrl.Finish() 431 432 req := ociCore.ListVolumeAttachmentsRequest{ 433 CompartmentId: &compartmentID, 434 InstanceId: s.volumes[0].GetInstanceId(), 435 } 436 resp := ociCore.ListVolumeAttachmentsResponse{ 437 Items: s.volumes, 438 } 439 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), req).Return(resp, nil) 440 441 obtained, err := s.client.ListVolumeAttachments(ctx.TODO(), &compartmentID, s.volumes[0].GetInstanceId()) 442 c.Assert(err, jc.ErrorIsNil) 443 c.Assert(obtained, gc.DeepEquals, s.volumes) 444 } 445 446 func (s *computeClientSuite) TestListVolumeAttachmentsPageN(c *gc.C) { 447 ctrl := s.setupMocks(c) 448 defer ctrl.Finish() 449 450 req := ociCore.ListVolumeAttachmentsRequest{ 451 CompartmentId: &compartmentID, 452 InstanceId: s.volumes[0].GetInstanceId(), 453 } 454 resp := ociCore.ListVolumeAttachmentsResponse{ 455 Items: []ociCore.VolumeAttachment{s.volumes[0]}, 456 OpcNextPage: makeStringPointer("test-pagination"), 457 } 458 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), req).Return(resp, nil) 459 req.Page = resp.OpcNextPage 460 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), req).Return( 461 ociCore.ListVolumeAttachmentsResponse{ 462 Items: []ociCore.VolumeAttachment{s.volumes[1]}, 463 }, nil) 464 465 obtained, err := s.client.ListVolumeAttachments(ctx.TODO(), &compartmentID, s.volumes[0].GetInstanceId()) 466 c.Assert(err, jc.ErrorIsNil) 467 c.Assert(obtained, gc.DeepEquals, s.volumes) 468 } 469 470 func (s *computeClientSuite) TestListVolumeAttachmentsFail(c *gc.C) { 471 ctrl := s.setupMocks(c) 472 defer ctrl.Finish() 473 474 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), gomock.Any()).Return(ociCore.ListVolumeAttachmentsResponse{}, errors.BadRequestf("test fail")) 475 476 obtained, err := s.client.ListVolumeAttachments(ctx.TODO(), &compartmentID, s.volumes[0].GetInstanceId()) 477 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 478 c.Assert(obtained, gc.HasLen, 0) 479 } 480 481 func (s *computeClientSuite) TestListVolumeAttachmentsFailPageN(c *gc.C) { 482 ctrl := s.setupMocks(c) 483 defer ctrl.Finish() 484 485 req := ociCore.ListVolumeAttachmentsRequest{ 486 CompartmentId: &compartmentID, 487 InstanceId: s.volumes[0].GetInstanceId(), 488 } 489 resp := ociCore.ListVolumeAttachmentsResponse{ 490 Items: []ociCore.VolumeAttachment{s.volumes[0]}, 491 OpcNextPage: makeStringPointer("test-pagination"), 492 } 493 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), req).Return(resp, nil) 494 req.Page = resp.OpcNextPage 495 s.mockAPI.EXPECT().ListVolumeAttachments(gomock.Any(), req).Return(ociCore.ListVolumeAttachmentsResponse{}, errors.BadRequestf("test fail")) 496 497 obtained, err := s.client.ListVolumeAttachments(ctx.TODO(), &compartmentID, s.volumes[0].GetInstanceId()) 498 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 499 c.Assert(obtained, gc.HasLen, 0) 500 } 501 502 func (s *computeClientSuite) setupMocks(c *gc.C) *gomock.Controller { 503 ctrl := gomock.NewController(c) 504 505 s.mockAPI = testing.NewMockOCIComputeClient(ctrl) 506 s.client = &computeClient{s.mockAPI} 507 return ctrl 508 } 509 510 type networkClientSuite struct { 511 client *networkClient 512 mockAPI *testing.MockOCIVirtualNetworkingClient 513 vcns []ociCore.Vcn 514 subnets []ociCore.Subnet 515 gateways []ociCore.InternetGateway 516 tables []ociCore.RouteTable 517 securityLists []ociCore.SecurityList 518 } 519 520 func (s *networkClientSuite) SetUpSuite(c *gc.C) { 521 s.vcns = []ociCore.Vcn{ 522 { 523 CompartmentId: &compartmentID, 524 Id: makeStringPointer("idOne"), 525 }, 526 { 527 CompartmentId: &compartmentID, 528 Id: makeStringPointer("idTwo"), 529 }, 530 } 531 s.subnets = []ociCore.Subnet{ 532 { 533 CompartmentId: &compartmentID, 534 Id: makeStringPointer("fakeSubnetId"), 535 VcnId: s.vcns[0].Id, 536 }, { 537 CompartmentId: &compartmentID, 538 Id: makeStringPointer("fakeSubnetId2"), 539 VcnId: s.vcns[0].Id, 540 }, 541 } 542 s.gateways = []ociCore.InternetGateway{ 543 { 544 CompartmentId: &compartmentID, 545 Id: makeStringPointer("fakeGwId"), 546 VcnId: s.vcns[0].Id, 547 }, 548 { 549 CompartmentId: &compartmentID, 550 Id: makeStringPointer("fakeGwId2"), 551 VcnId: s.vcns[0].Id, 552 }, 553 } 554 s.tables = []ociCore.RouteTable{ 555 { 556 CompartmentId: &compartmentID, 557 Id: makeStringPointer("fakeRouteTableId"), 558 VcnId: s.vcns[0].Id, 559 }, 560 { 561 CompartmentId: &compartmentID, 562 Id: makeStringPointer("fakeRouteTableId2"), 563 VcnId: s.vcns[0].Id, 564 }, 565 } 566 s.securityLists = []ociCore.SecurityList{ 567 { 568 CompartmentId: &compartmentID, 569 VcnId: s.vcns[0].Id, 570 Id: makeStringPointer("fakeSecList"), 571 EgressSecurityRules: []ociCore.EgressSecurityRule{ 572 { 573 Destination: makeStringPointer("dst"), 574 }, 575 }, 576 IngressSecurityRules: []ociCore.IngressSecurityRule{ 577 { 578 Source: makeStringPointer("src"), 579 }, 580 }, 581 }, 582 { 583 CompartmentId: &compartmentID, 584 VcnId: s.vcns[0].Id, 585 Id: makeStringPointer("fakeSecList3"), 586 EgressSecurityRules: []ociCore.EgressSecurityRule{ 587 { 588 Destination: makeStringPointer("dst"), 589 }, 590 }, 591 IngressSecurityRules: []ociCore.IngressSecurityRule{ 592 { 593 Source: makeStringPointer("src"), 594 }, 595 }, 596 }, 597 } 598 } 599 600 func (s *networkClientSuite) TestListVcns(c *gc.C) { 601 ctrl := s.setupMocks(c) 602 defer ctrl.Finish() 603 604 s.mockAPI.EXPECT().ListVcns(gomock.Any(), gomock.Any()).Return(ociCore.ListVcnsResponse{ 605 Items: s.vcns, 606 }, nil) 607 608 obtained, err := s.client.ListVcns(ctx.TODO(), &compartmentID) 609 c.Assert(err, jc.ErrorIsNil) 610 c.Assert(obtained, gc.DeepEquals, s.vcns) 611 } 612 613 func (s *networkClientSuite) TestListVcnsPageN(c *gc.C) { 614 ctrl := s.setupMocks(c) 615 defer ctrl.Finish() 616 617 req := ociCore.ListVcnsRequest{ 618 CompartmentId: &compartmentID, 619 } 620 resp := ociCore.ListVcnsResponse{ 621 Items: []ociCore.Vcn{s.vcns[0]}, 622 OpcNextPage: makeStringPointer("test-pagination"), 623 } 624 s.mockAPI.EXPECT().ListVcns(gomock.Any(), req).Return(resp, nil) 625 req.Page = resp.OpcNextPage 626 s.mockAPI.EXPECT().ListVcns(gomock.Any(), req).Return(ociCore.ListVcnsResponse{ 627 Items: []ociCore.Vcn{s.vcns[1]}, 628 }, nil) 629 630 obtained, err := s.client.ListVcns(ctx.TODO(), &compartmentID) 631 c.Assert(err, jc.ErrorIsNil) 632 c.Assert(obtained, gc.DeepEquals, s.vcns) 633 } 634 635 func (s *networkClientSuite) TestListVcnsFail(c *gc.C) { 636 ctrl := s.setupMocks(c) 637 defer ctrl.Finish() 638 639 s.mockAPI.EXPECT().ListVcns(gomock.Any(), gomock.Any()).Return(ociCore.ListVcnsResponse{}, errors.BadRequestf("test fail")) 640 641 obtained, err := s.client.ListVcns(ctx.TODO(), &compartmentID) 642 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 643 c.Assert(obtained, gc.HasLen, 0) 644 } 645 646 func (s *networkClientSuite) TestListVcnsFailPageN(c *gc.C) { 647 ctrl := s.setupMocks(c) 648 defer ctrl.Finish() 649 650 req := ociCore.ListVcnsRequest{ 651 CompartmentId: &compartmentID, 652 } 653 resp := ociCore.ListVcnsResponse{ 654 Items: s.vcns, 655 OpcNextPage: makeStringPointer("test-pagination"), 656 } 657 s.mockAPI.EXPECT().ListVcns(gomock.Any(), req).Return(resp, nil) 658 req.Page = resp.OpcNextPage 659 s.mockAPI.EXPECT().ListVcns(gomock.Any(), req).Return(ociCore.ListVcnsResponse{}, errors.BadRequestf("test fail")) 660 661 obtained, err := s.client.ListVcns(ctx.TODO(), &compartmentID) 662 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 663 c.Assert(obtained, gc.HasLen, 0) 664 } 665 666 func (s *networkClientSuite) TestListSubnets(c *gc.C) { 667 ctrl := s.setupMocks(c) 668 defer ctrl.Finish() 669 670 req := ociCore.ListSubnetsRequest{ 671 CompartmentId: &compartmentID, 672 VcnId: s.vcns[0].Id, 673 } 674 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(ociCore.ListSubnetsResponse{ 675 Items: s.subnets, 676 }, nil) 677 678 obtained, err := s.client.ListSubnets(ctx.TODO(), &compartmentID, s.vcns[0].Id) 679 c.Assert(err, jc.ErrorIsNil) 680 c.Assert(obtained, gc.DeepEquals, s.subnets) 681 } 682 683 func (s *networkClientSuite) TestListSubnetsPageN(c *gc.C) { 684 ctrl := s.setupMocks(c) 685 defer ctrl.Finish() 686 687 req := ociCore.ListSubnetsRequest{ 688 CompartmentId: &compartmentID, 689 VcnId: s.vcns[0].Id, 690 } 691 resp := ociCore.ListSubnetsResponse{ 692 Items: []ociCore.Subnet{s.subnets[0]}, 693 OpcNextPage: makeStringPointer("test-pagination"), 694 } 695 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(resp, nil) 696 req.Page = resp.OpcNextPage 697 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(ociCore.ListSubnetsResponse{ 698 Items: []ociCore.Subnet{s.subnets[1]}, 699 }, nil) 700 701 obtained, err := s.client.ListSubnets(ctx.TODO(), &compartmentID, s.vcns[0].Id) 702 c.Assert(err, jc.ErrorIsNil) 703 c.Assert(obtained, gc.DeepEquals, s.subnets) 704 } 705 706 func (s *networkClientSuite) TestListSubnetsFail(c *gc.C) { 707 ctrl := s.setupMocks(c) 708 defer ctrl.Finish() 709 710 req := ociCore.ListSubnetsRequest{ 711 CompartmentId: &compartmentID, 712 VcnId: s.vcns[0].Id, 713 } 714 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(ociCore.ListSubnetsResponse{}, errors.BadRequestf("test fail")) 715 716 obtained, err := s.client.ListSubnets(ctx.TODO(), &compartmentID, s.vcns[0].Id) 717 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 718 c.Assert(obtained, gc.HasLen, 0) 719 } 720 721 func (s *networkClientSuite) TestListSubnetsFailPageN(c *gc.C) { 722 ctrl := s.setupMocks(c) 723 defer ctrl.Finish() 724 725 req := ociCore.ListSubnetsRequest{ 726 CompartmentId: &compartmentID, 727 VcnId: s.vcns[0].Id, 728 } 729 resp := ociCore.ListSubnetsResponse{ 730 Items: []ociCore.Subnet{s.subnets[0]}, 731 OpcNextPage: makeStringPointer("test-pagination"), 732 } 733 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(resp, nil) 734 req.Page = resp.OpcNextPage 735 s.mockAPI.EXPECT().ListSubnets(gomock.Any(), req).Return(ociCore.ListSubnetsResponse{}, errors.BadRequestf("test fail")) 736 737 obtained, err := s.client.ListSubnets(ctx.TODO(), &compartmentID, s.vcns[0].Id) 738 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 739 c.Assert(obtained, gc.HasLen, 0) 740 } 741 742 func (s *networkClientSuite) TestListInternetGateways(c *gc.C) { 743 ctrl := s.setupMocks(c) 744 defer ctrl.Finish() 745 746 req := ociCore.ListInternetGatewaysRequest{ 747 CompartmentId: &compartmentID, 748 VcnId: s.vcns[0].Id, 749 } 750 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(ociCore.ListInternetGatewaysResponse{ 751 Items: s.gateways, 752 }, nil) 753 754 obtained, err := s.client.ListInternetGateways(ctx.TODO(), &compartmentID, s.vcns[0].Id) 755 c.Assert(err, jc.ErrorIsNil) 756 c.Assert(obtained, gc.DeepEquals, s.gateways) 757 } 758 759 func (s *networkClientSuite) TestListInternetGatewaysPageN(c *gc.C) { 760 ctrl := s.setupMocks(c) 761 defer ctrl.Finish() 762 763 req := ociCore.ListInternetGatewaysRequest{ 764 CompartmentId: &compartmentID, 765 VcnId: s.vcns[0].Id, 766 } 767 resp := ociCore.ListInternetGatewaysResponse{ 768 Items: []ociCore.InternetGateway{s.gateways[0]}, 769 OpcNextPage: makeStringPointer("test-pagination"), 770 } 771 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(resp, nil) 772 req.Page = resp.OpcNextPage 773 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(ociCore.ListInternetGatewaysResponse{ 774 Items: []ociCore.InternetGateway{s.gateways[1]}, 775 }, nil) 776 777 obtained, err := s.client.ListInternetGateways(ctx.TODO(), &compartmentID, s.vcns[0].Id) 778 c.Assert(err, jc.ErrorIsNil) 779 c.Assert(obtained, gc.DeepEquals, s.gateways) 780 } 781 782 func (s *networkClientSuite) TestListInternetGatewaysFail(c *gc.C) { 783 ctrl := s.setupMocks(c) 784 defer ctrl.Finish() 785 786 req := ociCore.ListInternetGatewaysRequest{ 787 CompartmentId: &compartmentID, 788 VcnId: s.vcns[0].Id, 789 } 790 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(ociCore.ListInternetGatewaysResponse{}, errors.BadRequestf("test fail")) 791 792 obtained, err := s.client.ListInternetGateways(ctx.TODO(), &compartmentID, s.vcns[0].Id) 793 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 794 c.Assert(obtained, gc.HasLen, 0) 795 } 796 797 func (s *networkClientSuite) TestListInternetGatewaysFailPageN(c *gc.C) { 798 ctrl := s.setupMocks(c) 799 defer ctrl.Finish() 800 801 req := ociCore.ListInternetGatewaysRequest{ 802 CompartmentId: &compartmentID, 803 VcnId: s.vcns[0].Id, 804 } 805 resp := ociCore.ListInternetGatewaysResponse{ 806 Items: s.gateways, 807 OpcNextPage: makeStringPointer("test-pagination"), 808 } 809 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(resp, nil) 810 req.Page = resp.OpcNextPage 811 s.mockAPI.EXPECT().ListInternetGateways(gomock.Any(), req).Return(ociCore.ListInternetGatewaysResponse{}, errors.BadRequestf("test fail")) 812 813 obtained, err := s.client.ListInternetGateways(ctx.TODO(), &compartmentID, s.vcns[0].Id) 814 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 815 c.Assert(obtained, gc.HasLen, 0) 816 } 817 818 func (s *networkClientSuite) TestListRouteTables(c *gc.C) { 819 ctrl := s.setupMocks(c) 820 defer ctrl.Finish() 821 822 req := ociCore.ListRouteTablesRequest{ 823 CompartmentId: &compartmentID, 824 VcnId: s.vcns[0].Id, 825 } 826 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(ociCore.ListRouteTablesResponse{ 827 Items: s.tables, 828 }, nil) 829 830 obtained, err := s.client.ListRouteTables(ctx.TODO(), &compartmentID, s.vcns[0].Id) 831 c.Assert(err, jc.ErrorIsNil) 832 c.Assert(obtained, gc.DeepEquals, s.tables) 833 } 834 835 func (s *networkClientSuite) TestListRouteTablesPageN(c *gc.C) { 836 ctrl := s.setupMocks(c) 837 defer ctrl.Finish() 838 839 req := ociCore.ListRouteTablesRequest{ 840 CompartmentId: &compartmentID, 841 VcnId: s.vcns[0].Id, 842 } 843 resp := ociCore.ListRouteTablesResponse{ 844 Items: []ociCore.RouteTable{s.tables[0]}, 845 OpcNextPage: makeStringPointer("test-pagination"), 846 } 847 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(resp, nil) 848 req.Page = resp.OpcNextPage 849 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(ociCore.ListRouteTablesResponse{ 850 Items: []ociCore.RouteTable{s.tables[1]}, 851 }, nil) 852 853 obtained, err := s.client.ListRouteTables(ctx.TODO(), &compartmentID, s.vcns[0].Id) 854 c.Assert(err, jc.ErrorIsNil) 855 c.Assert(obtained, gc.DeepEquals, s.tables) 856 } 857 858 func (s *networkClientSuite) TestListRouteTablesFail(c *gc.C) { 859 ctrl := s.setupMocks(c) 860 defer ctrl.Finish() 861 862 req := ociCore.ListRouteTablesRequest{ 863 CompartmentId: &compartmentID, 864 VcnId: s.vcns[0].Id, 865 } 866 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(ociCore.ListRouteTablesResponse{}, errors.BadRequestf("test fail")) 867 868 obtained, err := s.client.ListRouteTables(ctx.TODO(), &compartmentID, s.vcns[0].Id) 869 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 870 c.Assert(obtained, gc.HasLen, 0) 871 } 872 873 func (s *networkClientSuite) TestListRouteTablesFailPageN(c *gc.C) { 874 ctrl := s.setupMocks(c) 875 defer ctrl.Finish() 876 877 req := ociCore.ListRouteTablesRequest{ 878 CompartmentId: &compartmentID, 879 VcnId: s.vcns[0].Id, 880 } 881 resp := ociCore.ListRouteTablesResponse{ 882 Items: []ociCore.RouteTable{s.tables[0]}, 883 OpcNextPage: makeStringPointer("test-pagination"), 884 } 885 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(resp, nil) 886 req.Page = resp.OpcNextPage 887 s.mockAPI.EXPECT().ListRouteTables(gomock.Any(), req).Return(ociCore.ListRouteTablesResponse{}, errors.BadRequestf("test fail")) 888 889 obtained, err := s.client.ListRouteTables(ctx.TODO(), &compartmentID, s.vcns[0].Id) 890 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 891 c.Assert(obtained, gc.HasLen, 0) 892 } 893 894 func (s *networkClientSuite) TestListSecurityLists(c *gc.C) { 895 ctrl := s.setupMocks(c) 896 defer ctrl.Finish() 897 898 req := ociCore.ListSecurityListsRequest{ 899 CompartmentId: &compartmentID, 900 VcnId: s.vcns[0].Id, 901 } 902 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(ociCore.ListSecurityListsResponse{ 903 Items: s.securityLists, 904 }, nil) 905 906 obtained, err := s.client.ListSecurityLists(ctx.TODO(), &compartmentID, s.vcns[0].Id) 907 c.Assert(err, jc.ErrorIsNil) 908 c.Assert(obtained, gc.DeepEquals, s.securityLists) 909 } 910 911 func (s *networkClientSuite) TestListSecurityListsPageN(c *gc.C) { 912 ctrl := s.setupMocks(c) 913 defer ctrl.Finish() 914 915 req := ociCore.ListSecurityListsRequest{ 916 CompartmentId: &compartmentID, 917 VcnId: s.vcns[0].Id, 918 } 919 resp := ociCore.ListSecurityListsResponse{ 920 Items: []ociCore.SecurityList{s.securityLists[0]}, 921 OpcNextPage: makeStringPointer("test-pagination"), 922 } 923 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(resp, nil) 924 req.Page = resp.OpcNextPage 925 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(ociCore.ListSecurityListsResponse{ 926 Items: []ociCore.SecurityList{s.securityLists[1]}, 927 }, nil) 928 929 obtained, err := s.client.ListSecurityLists(ctx.TODO(), &compartmentID, s.vcns[0].Id) 930 c.Assert(err, jc.ErrorIsNil) 931 c.Assert(obtained, gc.DeepEquals, s.securityLists) 932 } 933 934 func (s *networkClientSuite) TestListSecurityListsFail(c *gc.C) { 935 ctrl := s.setupMocks(c) 936 defer ctrl.Finish() 937 938 req := ociCore.ListSecurityListsRequest{ 939 CompartmentId: &compartmentID, 940 VcnId: s.vcns[0].Id, 941 } 942 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(ociCore.ListSecurityListsResponse{}, errors.BadRequestf("test fail")) 943 944 obtained, err := s.client.ListSecurityLists(ctx.TODO(), &compartmentID, s.vcns[0].Id) 945 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 946 c.Assert(obtained, gc.HasLen, 0) 947 } 948 949 func (s *networkClientSuite) TestListSecurityListsFailPageN(c *gc.C) { 950 ctrl := s.setupMocks(c) 951 defer ctrl.Finish() 952 953 req := ociCore.ListSecurityListsRequest{ 954 CompartmentId: &compartmentID, 955 VcnId: s.vcns[0].Id, 956 } 957 resp := ociCore.ListSecurityListsResponse{ 958 Items: []ociCore.SecurityList{s.securityLists[0]}, 959 OpcNextPage: makeStringPointer("test-pagination"), 960 } 961 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(resp, nil) 962 req.Page = resp.OpcNextPage 963 s.mockAPI.EXPECT().ListSecurityLists(gomock.Any(), req).Return(ociCore.ListSecurityListsResponse{}, errors.BadRequestf("test fail")) 964 965 obtained, err := s.client.ListSecurityLists(ctx.TODO(), &compartmentID, s.vcns[0].Id) 966 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 967 c.Assert(obtained, gc.HasLen, 0) 968 } 969 970 func (s *networkClientSuite) setupMocks(c *gc.C) *gomock.Controller { 971 ctrl := gomock.NewController(c) 972 973 s.mockAPI = testing.NewMockOCIVirtualNetworkingClient(ctrl) 974 s.client = &networkClient{s.mockAPI} 975 return ctrl 976 } 977 978 type storageClientSuite struct { 979 client *storageClient 980 mockAPI *testing.MockOCIStorageClient 981 } 982 983 func (s *storageClientSuite) TestListVolumes(c *gc.C) { 984 ctrl := s.setupMocks(c) 985 defer ctrl.Finish() 986 987 vol := newVolume(61440) 988 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return(ociCore.ListVolumesResponse{ 989 Items: []ociCore.Volume{vol}, 990 }, nil) 991 992 obtained, err := s.client.ListVolumes(ctx.TODO(), &compartmentID) 993 c.Assert(err, jc.ErrorIsNil) 994 c.Assert(obtained, gc.DeepEquals, []ociCore.Volume{vol}) 995 } 996 997 func (s *storageClientSuite) TestListVolumesPageN(c *gc.C) { 998 ctrl := s.setupMocks(c) 999 defer ctrl.Finish() 1000 1001 vol := newVolume(61440) 1002 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return(ociCore.ListVolumesResponse{ 1003 Items: []ociCore.Volume{vol}, 1004 OpcNextPage: makeStringPointer("test-pagination"), 1005 }, nil) 1006 1007 vol2 := newVolume(87906) 1008 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return(ociCore.ListVolumesResponse{ 1009 Items: []ociCore.Volume{vol2}, 1010 }, nil) 1011 1012 obtained, err := s.client.ListVolumes(ctx.TODO(), &compartmentID) 1013 c.Assert(err, jc.ErrorIsNil) 1014 c.Assert(obtained, gc.DeepEquals, []ociCore.Volume{vol, vol2}) 1015 } 1016 1017 func (s *storageClientSuite) TestListVolumesFail(c *gc.C) { 1018 ctrl := s.setupMocks(c) 1019 defer ctrl.Finish() 1020 1021 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return( 1022 ociCore.ListVolumesResponse{}, errors.BadRequestf("test fail")) 1023 1024 obtained, err := s.client.ListVolumes(ctx.TODO(), &compartmentID) 1025 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 1026 c.Assert(obtained, gc.HasLen, 0) 1027 } 1028 1029 func (s *storageClientSuite) TestListVolumesFailPageN(c *gc.C) { 1030 ctrl := s.setupMocks(c) 1031 defer ctrl.Finish() 1032 1033 vol := newVolume(61440) 1034 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return(ociCore.ListVolumesResponse{ 1035 Items: []ociCore.Volume{vol}, 1036 OpcNextPage: makeStringPointer("test-pagination"), 1037 }, nil) 1038 s.mockAPI.EXPECT().ListVolumes(gomock.Any(), gomock.Any()).Return( 1039 ociCore.ListVolumesResponse{}, errors.BadRequestf("test fail")) 1040 1041 obtained, err := s.client.ListVolumes(ctx.TODO(), &compartmentID) 1042 c.Assert(err, jc.Satisfies, errors.IsBadRequest) 1043 c.Assert(obtained, gc.HasLen, 0) 1044 } 1045 1046 func (s *storageClientSuite) setupMocks(c *gc.C) *gomock.Controller { 1047 ctrl := gomock.NewController(c) 1048 1049 s.mockAPI = testing.NewMockOCIStorageClient(ctrl) 1050 s.client = &storageClient{s.mockAPI} 1051 return ctrl 1052 } 1053 1054 func newVolume(size int64) ociCore.Volume { 1055 return ociCore.Volume{ 1056 AvailabilityDomain: makeStringPointer("fakeZone1"), 1057 CompartmentId: &compartmentID, 1058 Id: makeStringPointer("fakeVolumeId"), 1059 LifecycleState: ociCore.VolumeLifecycleStateProvisioning, 1060 FreeformTags: map[string]string{ 1061 tags.JujuModel: "fake-uuid", 1062 }, 1063 SizeInGBs: &size, 1064 } 1065 }