github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv2/alb_test.go (about) 1 package containerv2 2 3 import ( 4 "log" 5 "net/http" 6 7 bluemix "github.com/IBM-Cloud/bluemix-go" 8 "github.com/IBM-Cloud/bluemix-go/client" 9 bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 "github.com/onsi/gomega/ghttp" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("Albs", func() { 19 var server *ghttp.Server 20 AfterEach(func() { 21 server.Close() 22 }) 23 24 //Create 25 Describe("Create", func() { 26 Context("When creating alb is successful", func() { 27 BeforeEach(func() { 28 server = ghttp.NewServer() 29 server.AppendHandlers( 30 ghttp.CombineHandlers( 31 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/createAlb"), 32 ghttp.VerifyJSON(`{"cluster":"345","type":"public","enableByDefault":true,"zone": "us-south-1", "ingressImage": "1.5.1_5367_iks"}`), 33 ghttp.RespondWith(http.StatusCreated, `{"alb":"1234", "cluster":"clusterID"}`), 34 ), 35 ) 36 }) 37 38 It("should create Alb in a cluster", func() { 39 target := ClusterTargetHeader{} 40 params := AlbCreateReq{ 41 Cluster: "345", Type: "public", EnableByDefault: true, ZoneAlb: "us-south-1", IngressImage: "1.5.1_5367_iks", 42 } 43 AlbResp, err := newAlbs(server.URL()).CreateAlb(params, target) 44 Expect(AlbResp.Alb).To(Equal("1234")) 45 Expect(AlbResp.Cluster).To(Equal("clusterID")) 46 Expect(err).NotTo(HaveOccurred()) 47 }) 48 }) 49 Context("When creating is unsuccessful", func() { 50 BeforeEach(func() { 51 server = ghttp.NewServer() 52 server.SetAllowUnhandledRequests(true) 53 server.AppendHandlers( 54 ghttp.CombineHandlers( 55 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/createAlb"), 56 ghttp.VerifyJSON(`{"cluster":"345","type":"public","enableByDefault":true,"zone": "us-south-1","ingressImage": "1.5.1_5367_iks"} 57 `), 58 ghttp.RespondWith(http.StatusInternalServerError, `Failed to create alb`), 59 ), 60 ) 61 }) 62 63 It("should return error during creating alb", func() { 64 params := AlbCreateReq{ 65 Cluster: "345", Type: "public", EnableByDefault: true, ZoneAlb: "us-south-1", IngressImage: "1.5.1_5367_iks", 66 } 67 target := ClusterTargetHeader{} 68 _, err := newAlbs(server.URL()).CreateAlb(params, target) 69 Expect(err).To(HaveOccurred()) 70 }) 71 }) 72 }) 73 74 //Enable 75 Describe("Enable", func() { 76 Context("When Enabling alb is successful", func() { 77 BeforeEach(func() { 78 server = ghttp.NewServer() 79 server.AppendHandlers( 80 ghttp.CombineHandlers( 81 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/enableAlb"), 82 ghttp.VerifyJSON(`{"albBuild":"579","albID":"private-crbm64u3ed02o93vv36hb0-alb1","albType":"private","authBuild":"341","cluster":"345","createdDate":"","disableDeployment":true,"loadBalancerHostname":"","name":"","numOfInstances":"","resize":true,"state":"disabled","status":"","enable":true,"zone": "us-south-1"}`), 83 ghttp.RespondWith(http.StatusCreated, `{}`), 84 ), 85 ) 86 }) 87 88 It("should enable Alb in a cluster", func() { 89 target := ClusterTargetHeader{} 90 params := AlbConfig{ 91 AlbBuild: "579", AlbID: "private-crbm64u3ed02o93vv36hb0-alb1", AuthBuild: "341", Cluster: "345", CreatedDate: "", DisableDeployment: true, LoadBalancerHostname: "", AlbType: "private", Name: "", NumOfInstances: "", Resize: true, State: "disabled", Status: "", Enable: true, ZoneAlb: "us-south-1", 92 } 93 err := newAlbs(server.URL()).EnableAlb(params, target) 94 Expect(err).NotTo(HaveOccurred()) 95 }) 96 }) 97 Context("When enabling is unsuccessful", func() { 98 BeforeEach(func() { 99 server = ghttp.NewServer() 100 server.SetAllowUnhandledRequests(true) 101 server.AppendHandlers( 102 ghttp.CombineHandlers( 103 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/enableAlb"), 104 ghttp.VerifyJSON(`{"albBuild":"579","albID":"private-crbm64u3ed02o93vv36hb0-alb1","albType":"private","authBuild":"341","cluster":"345","createdDate":"","disableDeployment":true,"loadBalancerHostname":"","name":"","numOfInstances":"","resize":true,"state":"disabled","status":"","enable":true,"zone": "us-south-1"} 105 `), 106 ghttp.RespondWith(http.StatusInternalServerError, `Failed to enable alb`), 107 ), 108 ) 109 }) 110 111 It("should return error during enabling alb", func() { 112 params := AlbConfig{ 113 AlbBuild: "579", AlbID: "private-crbm64u3ed02o93vv36hb0-alb1", AlbType: "private", AuthBuild: "341", CreatedDate: "", DisableDeployment: true, Enable: true, LoadBalancerHostname: "", Name: "", NumOfInstances: "", Resize: true, State: "disabled", Status: "", Cluster: "345", ZoneAlb: "us-south-1", 114 } 115 target := ClusterTargetHeader{} 116 err := newAlbs(server.URL()).EnableAlb(params, target) 117 Expect(err).To(HaveOccurred()) 118 }) 119 }) 120 }) 121 122 //Disable 123 Describe("Disable", func() { 124 Context("When Disabling alb is successful", func() { 125 BeforeEach(func() { 126 server = ghttp.NewServer() 127 server.AppendHandlers( 128 ghttp.CombineHandlers( 129 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/disableAlb"), 130 ghttp.VerifyJSON(`{"albBuild":"579","albID":"private-crbm64u3ed02o93vv36hb0-alb1","albType":"private","authBuild":"341","cluster":"345","createdDate":"","disableDeployment":true,"loadBalancerHostname":"","name":"","numOfInstances":"","resize":true,"state":"disabled","status":"","enable":true,"zone": "us-south-1"}`), 131 ghttp.RespondWith(http.StatusCreated, `{}`), 132 ), 133 ) 134 }) 135 136 It("should disable Alb in a cluster", func() { 137 target := ClusterTargetHeader{} 138 params := AlbConfig{ 139 AlbBuild: "579", AlbID: "private-crbm64u3ed02o93vv36hb0-alb1", AlbType: "private", AuthBuild: "341", CreatedDate: "", DisableDeployment: true, Enable: true, LoadBalancerHostname: "", Name: "", NumOfInstances: "", Resize: true, State: "disabled", Status: "", Cluster: "345", ZoneAlb: "us-south-1", 140 } 141 err := newAlbs(server.URL()).DisableAlb(params, target) 142 Expect(err).NotTo(HaveOccurred()) 143 }) 144 }) 145 Context("When disabling is unsuccessful", func() { 146 BeforeEach(func() { 147 server = ghttp.NewServer() 148 server.SetAllowUnhandledRequests(true) 149 server.AppendHandlers( 150 ghttp.CombineHandlers( 151 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/vpc/disableAlb"), 152 ghttp.VerifyJSON(`{"albBuild":"579","albID":"private-crbm64u3ed02o93vv36hb0-alb1","albType":"private","authBuild":"341","cluster":"345","createdDate":"","disableDeployment":true,"loadBalancerHostname":"","name":"","numOfInstances":"","resize":true,"state":"disabled","status":"","enable":true,"zone": "us-south-1"} 153 `), 154 ghttp.RespondWith(http.StatusInternalServerError, `Failed to disable alb`), 155 ), 156 ) 157 }) 158 159 It("should return error during disabling alb", func() { 160 params := AlbConfig{ 161 AlbBuild: "579", AlbID: "private-crbm64u3ed02o93vv36hb0-alb1", AlbType: "private", AuthBuild: "341", CreatedDate: "", DisableDeployment: true, Enable: true, LoadBalancerHostname: "", Name: "", NumOfInstances: "", Resize: true, State: "disabled", Status: "", Cluster: "345", ZoneAlb: "us-south-1", 162 } 163 target := ClusterTargetHeader{} 164 err := newAlbs(server.URL()).DisableAlb(params, target) 165 Expect(err).To(HaveOccurred()) 166 }) 167 }) 168 }) 169 170 //GetAlbs 171 Describe("Get", func() { 172 Context("When Get Alb is successful", func() { 173 BeforeEach(func() { 174 server = ghttp.NewServer() 175 server.AppendHandlers( 176 ghttp.CombineHandlers( 177 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getAlb"), 178 ghttp.RespondWith(http.StatusCreated, `{"albBuild": "string","albID": "string","albType": "string","authBuild": "string","cluster": "string","createdDate": "string","disableDeployment": true,"enable": true,"loadBalancerHostname": "string","name": "string","numOfInstances": "string","resize": true,"state": "string","status": "string","zone": "string"}`), 179 ), 180 ) 181 }) 182 183 It("should get Alb in a cluster", func() { 184 target := ClusterTargetHeader{} 185 186 _, err := newAlbs(server.URL()).GetAlb("aaa", target) 187 Expect(err).NotTo(HaveOccurred()) 188 }) 189 }) 190 Context("When get alb is unsuccessful", func() { 191 BeforeEach(func() { 192 server = ghttp.NewServer() 193 server.SetAllowUnhandledRequests(true) 194 server.AppendHandlers( 195 ghttp.CombineHandlers( 196 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getAlb"), 197 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get alb`), 198 ), 199 ) 200 }) 201 202 It("should return error during get alb", func() { 203 target := ClusterTargetHeader{} 204 _, err := newAlbs(server.URL()).GetAlb("aaa", target) 205 Expect(err).To(HaveOccurred()) 206 }) 207 }) 208 }) 209 210 // UpdateAlb 211 Describe("UpdateAlb", func() { 212 Context("When Update Alb is successful", func() { 213 BeforeEach(func() { 214 server = ghttp.NewServer() 215 server.AppendHandlers( 216 ghttp.CombineHandlers( 217 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/updateAlb"), 218 ghttp.RespondWith(http.StatusOK, `{"clusterID":"myCluster"}`), 219 ), 220 ) 221 }) 222 223 It("should update Alb in a cluster", func() { 224 target := ClusterTargetHeader{} 225 updateReq := UpdateALBReq{ 226 ClusterID: "myCluster", 227 ALBBuild: "1.8.1_5384_iks", 228 ALBList: []string{ 229 "public-crck9aaedd0p8vjmqa0asg-alb1", 230 }, 231 } 232 err := newAlbs(server.URL()).UpdateAlb(updateReq, target) 233 Expect(err).NotTo(HaveOccurred()) 234 }) 235 }) 236 Context("When update alb is unsuccessful", func() { 237 BeforeEach(func() { 238 server = ghttp.NewServer() 239 server.SetAllowUnhandledRequests(true) 240 server.AppendHandlers( 241 ghttp.CombineHandlers( 242 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/updateAlb"), 243 ghttp.RespondWith(http.StatusInternalServerError, `Failed to update alb`), 244 ), 245 ) 246 }) 247 248 It("should return error during get alb", func() { 249 target := ClusterTargetHeader{} 250 updateReq := UpdateALBReq{ 251 ClusterID: "myCluster", 252 ALBBuild: "1.8.1_5384_iks", 253 ALBList: []string{ 254 "public-crck9aaedd0p8vjmqa0asg-alb1", 255 }, 256 } 257 err := newAlbs(server.URL()).UpdateAlb(updateReq, target) 258 Expect(err).To(HaveOccurred()) 259 }) 260 }) 261 }) 262 263 // ListClusterAlbs 264 Describe("ListClusterAlbs", func() { 265 Context("When List Albs is successful", func() { 266 BeforeEach(func() { 267 server = ghttp.NewServer() 268 server.AppendHandlers( 269 ghttp.CombineHandlers( 270 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getClusterAlbs"), 271 ghttp.RespondWith(http.StatusOK, `{"alb":[{"albID":"private-crclusterid-alb1","cluster":"clusterid","name":"","albType":"private","enable":true,"state":"enabled","createdDate":"","numOfInstances":"2","resize":false,"zone":"testzone","disableDeployment":false,"albBuild":"1.8.1_5384_iks","authBuild":"","loadBalancerHostname":"test1-us-south.lb.test.appdomain.cloud","status":"healthy"},{"albID":"public-crclusterid-alb1","cluster":"clusterid","name":"","albType":"public","enable":true,"state":"enabled","createdDate":"","numOfInstances":"2","resize":false,"zone":"testzone","disableDeployment":false,"albBuild":"1.8.1_5384_iks","authBuild":"","loadBalancerHostname":"test2-us-south.lb.test.appdomain.cloud","status":"healthy"}]}`), 272 ), 273 ) 274 }) 275 276 It("should list Albs in a cluster", func() { 277 target := ClusterTargetHeader{} 278 _, err := newAlbs(server.URL()).ListClusterAlbs("clusterid", target) 279 Expect(err).NotTo(HaveOccurred()) 280 }) 281 }) 282 Context("When List Albs is unsuccessful", func() { 283 BeforeEach(func() { 284 server = ghttp.NewServer() 285 server.SetAllowUnhandledRequests(true) 286 server.AppendHandlers( 287 ghttp.CombineHandlers( 288 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getClusterAlbs"), 289 ghttp.RespondWith(http.StatusInternalServerError, `Failed to list albs`), 290 ), 291 ) 292 }) 293 294 It("should return error during get alb", func() { 295 target := ClusterTargetHeader{} 296 _, err := newAlbs(server.URL()).ListClusterAlbs("clusterid", target) 297 Expect(err).To(HaveOccurred()) 298 }) 299 }) 300 }) 301 302 // ListAlbImages 303 Describe("ListAlbImages", func() { 304 Context("When List Alb images is successful", func() { 305 BeforeEach(func() { 306 server = ghttp.NewServer() 307 server.AppendHandlers( 308 ghttp.CombineHandlers( 309 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getAlbImages"), 310 ghttp.RespondWith(http.StatusOK, `{"defaultK8sVersion":"1.8.1_5384_iks","supportedK8sVersions":["1.5.1_5407_iks","1.6.4_5406_iks","1.8.1_5384_iks"]}`), 311 ), 312 ) 313 }) 314 315 It("should list Alb images", func() { 316 target := ClusterTargetHeader{} 317 _, err := newAlbs(server.URL()).ListAlbImages(target) 318 Expect(err).NotTo(HaveOccurred()) 319 }) 320 }) 321 Context("When List Alb images is unsuccessful", func() { 322 BeforeEach(func() { 323 server = ghttp.NewServer() 324 server.SetAllowUnhandledRequests(true) 325 server.AppendHandlers( 326 ghttp.CombineHandlers( 327 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getAlbImages"), 328 ghttp.RespondWith(http.StatusInternalServerError, `Failed to list alb images`), 329 ), 330 ) 331 }) 332 333 It("should return error during get alb images", func() { 334 target := ClusterTargetHeader{} 335 _, err := newAlbs(server.URL()).ListAlbImages(target) 336 Expect(err).To(HaveOccurred()) 337 }) 338 }) 339 }) 340 341 // GetIngressStatus 342 Describe("GetIngressStatus", func() { 343 Context("When GetIngressStatus is successful", func() { 344 BeforeEach(func() { 345 server = ghttp.NewServer() 346 server.AppendHandlers( 347 ghttp.CombineHandlers( 348 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getStatus"), 349 ghttp.RespondWith(http.StatusOK, `{"cluster":"clusterid","enabled":true,"status":"healthy","nonTranslatedStatus":"HEALTHY","message":"All Ingress components are healthy.","StatusList":[{"component":"ingress-controller-configmap","status":"healthy","type":"cluster"},{"component":"alb-healthcheck-ingress","status":"healthy","type":"cluster"},{"component":"public-crclusterid-alb1","status":"healthy","type":"alb"},{"component":"ingressHostname.us-south.containers.appdomain.cloud","status":"healthy","type":"subdomain"},{"component":"default/ingressHostname","status":"healthy","type":"secret"},{"component":"ibm-cert-store/ingressHostname","status":"healthy","type":"secret"},{"component":"kube-system/ingressHostname","status":"healthy","type":"secret"}],"generalComponentStatus":[{"component":"ingress-controller-configmap","status":["healthy"]},{"component":"alb-healthcheck-ingress","status":["healthy"]}],"albStatus":[{"component":"public-crclusterid-alb1","status":["healthy"]}],"subdomainStatus":[{"component":"ingressHostname.us-south.containers.appdomain.cloud","status":["healthy"]}],"secretStatus":[{"component":"default/ingressHostname","status":["healthy"]},{"component":"ibm-cert-store/ingressHostname","status":["healthy"]},{"component":"kube-system/ingressHostname","status":["healthy"]}],"ignoredErrors":[]}`), 350 ), 351 ) 352 }) 353 354 It("should get ingress status in a cluster", func() { 355 target := ClusterTargetHeader{} 356 _, err := newAlbs(server.URL()).GetIngressStatus("clusterid", target) 357 Expect(err).NotTo(HaveOccurred()) 358 }) 359 }) 360 Context("When GetIngressStatus is unsuccessful", func() { 361 BeforeEach(func() { 362 server = ghttp.NewServer() 363 server.SetAllowUnhandledRequests(true) 364 server.AppendHandlers( 365 ghttp.CombineHandlers( 366 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getStatus"), 367 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get ingress status`), 368 ), 369 ) 370 }) 371 372 It("should return error during get ingress status", func() { 373 target := ClusterTargetHeader{} 374 _, err := newAlbs(server.URL()).GetIngressStatus("clusterid", target) 375 Expect(err).To(HaveOccurred()) 376 }) 377 }) 378 }) 379 380 // SetAlbClusterHealthCheckConfig 381 Describe("SetAlbClusterHealthCheckConfig", func() { 382 clusterHcConfig := ALBClusterHealthCheckConfig{ 383 Cluster: "clusterid", 384 Enable: false, 385 } 386 387 Context("When SetAlbClusterHealthCheckConfig is successful", func() { 388 BeforeEach(func() { 389 server = ghttp.NewServer() 390 server.AppendHandlers( 391 ghttp.CombineHandlers( 392 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/setIngressClusterHealthcheck"), 393 ghttp.RespondWith(http.StatusOK, `{"cluster":"clusterid"}`), 394 ), 395 ) 396 }) 397 398 It("should set ingress in cluster health checker config", func() { 399 target := ClusterTargetHeader{} 400 err := newAlbs(server.URL()).SetAlbClusterHealthCheckConfig(clusterHcConfig, target) 401 Expect(err).NotTo(HaveOccurred()) 402 }) 403 }) 404 Context("When SetAlbClusterHealthCheckConfig is unsuccessful", func() { 405 BeforeEach(func() { 406 server = ghttp.NewServer() 407 server.SetAllowUnhandledRequests(true) 408 server.AppendHandlers( 409 ghttp.CombineHandlers( 410 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/setIngressClusterHealthcheck"), 411 ghttp.RespondWith(http.StatusInternalServerError, `Failed to set ingress in cluster health checkher config`), 412 ), 413 ) 414 }) 415 416 It("should return error during set ingress in cluster health checkher config", func() { 417 target := ClusterTargetHeader{} 418 err := newAlbs(server.URL()).SetAlbClusterHealthCheckConfig(clusterHcConfig, target) 419 Expect(err).To(HaveOccurred()) 420 }) 421 }) 422 }) 423 424 // GetIngressStatus 425 Describe("GetIngressStatus", func() { 426 Context("When GetIngressStatus is successful", func() { 427 BeforeEach(func() { 428 server = ghttp.NewServer() 429 server.AppendHandlers( 430 ghttp.CombineHandlers( 431 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getIngressClusterHealthcheck"), 432 ghttp.RespondWith(http.StatusOK, `{ "cluster": "ckdo7li2075cidkk3pu0", "enable": true }`), 433 ), 434 ) 435 }) 436 437 It("should get ingress in cluster health checker config", func() { 438 target := ClusterTargetHeader{} 439 _, err := newAlbs(server.URL()).GetAlbClusterHealthCheckConfig("clusterid", target) 440 Expect(err).NotTo(HaveOccurred()) 441 }) 442 }) 443 Context("When GetIngressStatus is unsuccessful", func() { 444 BeforeEach(func() { 445 server = ghttp.NewServer() 446 server.SetAllowUnhandledRequests(true) 447 server.AppendHandlers( 448 ghttp.CombineHandlers( 449 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/getIngressClusterHealthcheck"), 450 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get ingress in cluster health checker`), 451 ), 452 ) 453 }) 454 455 It("should return error during get ingress in cluster health checker", func() { 456 target := ClusterTargetHeader{} 457 _, err := newAlbs(server.URL()).GetAlbClusterHealthCheckConfig("clusterid", target) 458 Expect(err).To(HaveOccurred()) 459 }) 460 }) 461 }) 462 463 // GetIgnoredIngressStatusErrors 464 Describe("GetIgnoredIngressStatusErrors", func() { 465 Context("When GetIgnoredIngressStatusErrors is successful", func() { 466 BeforeEach(func() { 467 server = ghttp.NewServer() 468 server.AppendHandlers( 469 ghttp.CombineHandlers( 470 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/listIgnoredIngressStatusErrors"), 471 ghttp.RespondWith(http.StatusOK, `{ "cluster": "mycluster", "ignoredErrors": ["ERRAHCF"] }`), 472 ), 473 ) 474 }) 475 476 It("should get ignored error codes", func() { 477 target := ClusterTargetHeader{} 478 _, err := newAlbs(server.URL()).GetIgnoredIngressStatusErrors("mycluster", target) 479 Expect(err).NotTo(HaveOccurred()) 480 }) 481 }) 482 Context("When GetIgnoredIngressStatusErrors is unsuccessful", func() { 483 BeforeEach(func() { 484 server = ghttp.NewServer() 485 server.SetAllowUnhandledRequests(true) 486 server.AppendHandlers( 487 ghttp.CombineHandlers( 488 ghttp.VerifyRequest(http.MethodGet, "/v2/alb/listIgnoredIngressStatusErrors"), 489 ghttp.RespondWith(http.StatusInternalServerError, `Failed to list ignored error codes`), 490 ), 491 ) 492 }) 493 494 It("should return error during get ignored error codes", func() { 495 target := ClusterTargetHeader{} 496 _, err := newAlbs(server.URL()).GetIgnoredIngressStatusErrors("mycluster", target) 497 Expect(err).To(HaveOccurred()) 498 }) 499 }) 500 }) 501 502 // AddIgnoredIngressStatusErrors 503 Describe("AddIgnoredIngressStatusErrors", func() { 504 ignoredErrors := IgnoredIngressStatusErrors{ 505 Cluster: "mycluster", 506 IgnoredErrors: []string{ 507 "ERRAHCF", 508 }, 509 } 510 Context("When AddIgnoredIngressStatusErrors is successful", func() { 511 BeforeEach(func() { 512 server = ghttp.NewServer() 513 server.AppendHandlers( 514 ghttp.CombineHandlers( 515 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/addIgnoredIngressStatusErrors"), 516 ghttp.RespondWith(http.StatusOK, `{ "cluster": "mycluster" }`), 517 ), 518 ) 519 }) 520 521 It("should set ingnored error codes", func() { 522 target := ClusterTargetHeader{} 523 err := newAlbs(server.URL()).AddIgnoredIngressStatusErrors(ignoredErrors, target) 524 Expect(err).NotTo(HaveOccurred()) 525 }) 526 }) 527 Context("When AddIgnoredIngressStatusErrors is unsuccessful", func() { 528 BeforeEach(func() { 529 server = ghttp.NewServer() 530 server.SetAllowUnhandledRequests(true) 531 server.AppendHandlers( 532 ghttp.CombineHandlers( 533 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/addIgnoredIngressStatusErrors"), 534 ghttp.RespondWith(http.StatusInternalServerError, `Failed to set ignored error codes`), 535 ), 536 ) 537 }) 538 539 It("should return error during set ignored error codes", func() { 540 target := ClusterTargetHeader{} 541 err := newAlbs(server.URL()).AddIgnoredIngressStatusErrors(ignoredErrors, target) 542 Expect(err).To(HaveOccurred()) 543 }) 544 }) 545 }) 546 547 // RemoveIgnoredIngressStatusErrors 548 Describe("RemoveIgnoredIngressStatusErrors", func() { 549 ignoredErrors := IgnoredIngressStatusErrors{ 550 Cluster: "mycluster", 551 IgnoredErrors: []string{ 552 "ERRAHCF", 553 }, 554 } 555 Context("When RemoveIgnoredIngressStatusErrors is successful", func() { 556 BeforeEach(func() { 557 server = ghttp.NewServer() 558 server.AppendHandlers( 559 ghttp.CombineHandlers( 560 ghttp.VerifyRequest(http.MethodDelete, "/v2/alb/removeIgnoredIngressStatusErrors"), 561 ghttp.RespondWith(http.StatusOK, `{ "cluster": "mycluster" }`), 562 ), 563 ) 564 }) 565 566 It("should remove ingnored error codes", func() { 567 target := ClusterTargetHeader{} 568 err := newAlbs(server.URL()).RemoveIgnoredIngressStatusErrors(ignoredErrors, target) 569 Expect(err).NotTo(HaveOccurred()) 570 }) 571 }) 572 Context("When RemoveIgnoredIngressStatusErrors is unsuccessful", func() { 573 BeforeEach(func() { 574 server = ghttp.NewServer() 575 server.SetAllowUnhandledRequests(true) 576 server.AppendHandlers( 577 ghttp.CombineHandlers( 578 ghttp.VerifyRequest(http.MethodDelete, "/v2/alb/removeIgnoredIngressStatusErrors"), 579 ghttp.RespondWith(http.StatusInternalServerError, `Failed to remove ignored error codes`), 580 ), 581 ) 582 }) 583 584 It("should return error during remove ignored error codes", func() { 585 target := ClusterTargetHeader{} 586 err := newAlbs(server.URL()).RemoveIgnoredIngressStatusErrors(ignoredErrors, target) 587 Expect(err).To(HaveOccurred()) 588 }) 589 }) 590 }) 591 592 // SetIngressStatusState 593 Describe("SetIngressStatusState", func() { 594 ingressStatus := IngressStatusState{ 595 Cluster: "mycluster", 596 Enable: false, 597 } 598 Context("When SetIngressStatusState is successful", func() { 599 BeforeEach(func() { 600 server = ghttp.NewServer() 601 server.AppendHandlers( 602 ghttp.CombineHandlers( 603 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/setIngressStatusState"), 604 ghttp.RespondWith(http.StatusOK, `{ "cluster": "mycluster" }`), 605 ), 606 ) 607 }) 608 609 It("should set ingress status", func() { 610 target := ClusterTargetHeader{} 611 err := newAlbs(server.URL()).SetIngressStatusState(ingressStatus, target) 612 Expect(err).NotTo(HaveOccurred()) 613 }) 614 }) 615 Context("When SetIngressStatusState is unsuccessful", func() { 616 BeforeEach(func() { 617 server = ghttp.NewServer() 618 server.SetAllowUnhandledRequests(true) 619 server.AppendHandlers( 620 ghttp.CombineHandlers( 621 ghttp.VerifyRequest(http.MethodPost, "/v2/alb/setIngressStatusState"), 622 ghttp.RespondWith(http.StatusInternalServerError, `Failed to set ingress status`), 623 ), 624 ) 625 }) 626 627 It("should return error during set ingress status", func() { 628 target := ClusterTargetHeader{} 629 err := newAlbs(server.URL()).SetIngressStatusState(ingressStatus, target) 630 Expect(err).To(HaveOccurred()) 631 }) 632 }) 633 }) 634 635 // GetIngressLoadBalancerConfig 636 Describe("GetIngressLoadBalancerConfig", func() { 637 Context("When GetIngressLoadBalancerConfig is successful", func() { 638 BeforeEach(func() { 639 server = ghttp.NewServer() 640 server.AppendHandlers( 641 ghttp.CombineHandlers( 642 ghttp.VerifyRequest(http.MethodGet, "/ingress/v2/load-balancer/configuration"), 643 ghttp.RespondWith(http.StatusOK, `{ "cluster": "clusterid", "proxyProtocol": { "enable": true, "headerTimeout": 0 }, "type": "public" }`), 644 ), 645 ) 646 }) 647 648 It("should get lb config", func() { 649 target := ClusterTargetHeader{} 650 _, err := newAlbs(server.URL()).GetIngressLoadBalancerConfig("clusterid", "public", target) 651 Expect(err).NotTo(HaveOccurred()) 652 }) 653 }) 654 Context("When GetIngressLoadBalancerConfig is unsuccessful", func() { 655 BeforeEach(func() { 656 server = ghttp.NewServer() 657 server.SetAllowUnhandledRequests(true) 658 server.AppendHandlers( 659 ghttp.CombineHandlers( 660 ghttp.VerifyRequest(http.MethodGet, "/ingress/v2/load-balancer/configuration"), 661 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get lb config`), 662 ), 663 ) 664 }) 665 666 It("should return error during get lb config", func() { 667 target := ClusterTargetHeader{} 668 _, err := newAlbs(server.URL()).GetIngressLoadBalancerConfig("clusterid", "public", target) 669 Expect(err).To(HaveOccurred()) 670 }) 671 }) 672 }) 673 674 // UpdateIngressLoadBalancerConfig 675 Describe("UpdateIngressLoadBalancerConfig", func() { 676 lbConf := ALBLBConfig{ 677 Cluster: "clusterid", 678 Type: "public", 679 ProxyProtocol: &ALBLBProxyProtocolConfig{ 680 Enable: true, 681 }, 682 } 683 Context("When UpdateIngressLoadBalancerConfig is successful", func() { 684 BeforeEach(func() { 685 server = ghttp.NewServer() 686 server.AppendHandlers( 687 ghttp.CombineHandlers( 688 ghttp.VerifyRequest(http.MethodPatch, "/ingress/v2/load-balancer/configuration"), 689 ghttp.RespondWith(http.StatusOK, `{ "cluster": "clusterid", "proxyProtocol": { "enable": true, "headerTimeout": 0 }, "type": "public" }`), 690 ), 691 ) 692 }) 693 694 It("should update lb config", func() { 695 target := ClusterTargetHeader{} 696 err := newAlbs(server.URL()).UpdateIngressLoadBalancerConfig(lbConf, target) 697 Expect(err).NotTo(HaveOccurred()) 698 }) 699 }) 700 Context("When UpdateIngressLoadBalancerConfig is unsuccessful", func() { 701 BeforeEach(func() { 702 server = ghttp.NewServer() 703 server.SetAllowUnhandledRequests(true) 704 server.AppendHandlers( 705 ghttp.CombineHandlers( 706 ghttp.VerifyRequest(http.MethodPatch, "/ingress/v2/load-balancer/configuration"), 707 ghttp.RespondWith(http.StatusInternalServerError, `Failed to update lb config`), 708 ), 709 ) 710 }) 711 712 It("should return error during update lb config", func() { 713 target := ClusterTargetHeader{} 714 err := newAlbs(server.URL()).UpdateIngressLoadBalancerConfig(lbConf, target) 715 Expect(err).To(HaveOccurred()) 716 }) 717 }) 718 }) 719 720 // GetALBAutoscaleConfiguration 721 Describe("GetALBAutoscaleConfiguration", func() { 722 Context("When GetALBAutoscaleConfiguration is successful", func() { 723 BeforeEach(func() { 724 server = ghttp.NewServer() 725 server.AppendHandlers( 726 ghttp.CombineHandlers( 727 ghttp.VerifyRequest(http.MethodGet, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 728 ghttp.RespondWith(http.StatusOK, `{"config":{"minReplicas":2,"maxReplicas":4,"cpuAverageUtilization":600}}`), 729 ), 730 ) 731 }) 732 733 It("should get autoscale config", func() { 734 target := ClusterTargetHeader{} 735 _, err := newAlbs(server.URL()).GetALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", target) 736 Expect(err).NotTo(HaveOccurred()) 737 }) 738 }) 739 Context("When GetALBAutoscaleConfiguration is unsuccessful", func() { 740 BeforeEach(func() { 741 server = ghttp.NewServer() 742 server.SetAllowUnhandledRequests(true) 743 server.AppendHandlers( 744 ghttp.CombineHandlers( 745 ghttp.VerifyRequest(http.MethodGet, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 746 ghttp.RespondWith(http.StatusInternalServerError, `Failed to get autoscale config`), 747 ), 748 ) 749 }) 750 751 It("should return error during get autoscale config", func() { 752 target := ClusterTargetHeader{} 753 _, err := newAlbs(server.URL()).GetALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", target) 754 Expect(err).To(HaveOccurred()) 755 }) 756 }) 757 }) 758 759 // SetALBAutoscaleConfiguration 760 Describe("SetALBAutoscaleConfiguration", func() { 761 autoscaleConf := AutoscaleDetails{ 762 Config: &AutoscaleConfig{ 763 MinReplicas: 2, 764 MaxReplicas: 2, 765 CPUAverageUtilization: 600, 766 }, 767 } 768 Context("When SetALBAutoscaleConfiguration is successful", func() { 769 BeforeEach(func() { 770 server = ghttp.NewServer() 771 server.AppendHandlers( 772 ghttp.CombineHandlers( 773 ghttp.VerifyRequest(http.MethodPut, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 774 ghttp.RespondWith(http.StatusOK, ``), 775 ), 776 ) 777 }) 778 779 It("should set autoscale config", func() { 780 target := ClusterTargetHeader{} 781 err := newAlbs(server.URL()).SetALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", autoscaleConf, target) 782 Expect(err).NotTo(HaveOccurred()) 783 }) 784 }) 785 Context("When SetALBAutoscaleConfiguration is unsuccessful", func() { 786 BeforeEach(func() { 787 server = ghttp.NewServer() 788 server.SetAllowUnhandledRequests(true) 789 server.AppendHandlers( 790 ghttp.CombineHandlers( 791 ghttp.VerifyRequest(http.MethodPut, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 792 ghttp.RespondWith(http.StatusInternalServerError, `Failed to set autoscale config`), 793 ), 794 ) 795 }) 796 797 It("should return error during set autoscale config", func() { 798 target := ClusterTargetHeader{} 799 err := newAlbs(server.URL()).SetALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", autoscaleConf, target) 800 Expect(err).To(HaveOccurred()) 801 }) 802 }) 803 }) 804 805 // RemoveALBAutoscaleConfiguration 806 Describe("RemoveALBAutoscaleConfiguration", func() { 807 Context("When RemoveALBAutoscaleConfiguration is successful", func() { 808 BeforeEach(func() { 809 server = ghttp.NewServer() 810 server.AppendHandlers( 811 ghttp.CombineHandlers( 812 ghttp.VerifyRequest(http.MethodDelete, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 813 ghttp.RespondWith(http.StatusNoContent, `{"config":{"minReplicas":2,"maxReplicas":4,"cpuAverageUtilization":600}}`), 814 ), 815 ) 816 }) 817 818 It("should delete autoscale config", func() { 819 target := ClusterTargetHeader{} 820 err := newAlbs(server.URL()).RemoveALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", target) 821 Expect(err).NotTo(HaveOccurred()) 822 }) 823 }) 824 Context("When RemoveALBAutoscaleConfiguration is unsuccessful", func() { 825 BeforeEach(func() { 826 server = ghttp.NewServer() 827 server.SetAllowUnhandledRequests(true) 828 server.AppendHandlers( 829 ghttp.CombineHandlers( 830 ghttp.VerifyRequest(http.MethodDelete, "/ingress/v2/clusters/clusterid/albs/public-crclusterid-alb1/autoscale"), 831 ghttp.RespondWith(http.StatusInternalServerError, `Failed to delete autoscale config`), 832 ), 833 ) 834 }) 835 836 It("should return error during delete autoscale config", func() { 837 target := ClusterTargetHeader{} 838 err := newAlbs(server.URL()).RemoveALBAutoscaleConfiguration("clusterid", "public-crclusterid-alb1", target) 839 Expect(err).To(HaveOccurred()) 840 }) 841 }) 842 }) 843 844 }) 845 846 func newAlbs(url string) Alb { 847 848 sess, err := session.New() 849 if err != nil { 850 log.Fatal(err) 851 } 852 conf := sess.Config.Copy() 853 conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) 854 conf.Endpoint = &url 855 856 client := client.Client{ 857 Config: conf, 858 ServiceName: bluemix.VpcContainerService, 859 } 860 return newAlbAPI(&client) 861 }