github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/mccp/mccpv2/apps_test.go (about) 1 package mccpv2 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 "github.com/IBM-Cloud/bluemix-go/helpers" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 "github.com/onsi/gomega/ghttp" 15 ) 16 17 var _ = Describe("Apps", func() { 18 var server *ghttp.Server 19 AfterEach(func() { 20 server.Close() 21 }) 22 23 Describe("List", func() { 24 Context("Retrieving apps is successful", func() { 25 BeforeEach(func() { 26 server = ghttp.NewServer() 27 server.AppendHandlers( 28 ghttp.CombineHandlers( 29 ghttp.VerifyRequest(http.MethodGet, "/v2/apps"), 30 ghttp.RespondWith(http.StatusOK, `{ 31 "total_results": 3, 32 "total_pages": 1, 33 "prev_url": null, 34 "next_url": null, 35 "resources": [ 36 { 37 "metadata": { 38 "guid": "50a46e93-c9dc-4d85-b76a-4f23c95e7cda", 39 "url": "/v2/apps/50a46e93-c9dc-4d85-b76a-4f23c95e7cda", 40 "created_at": "2016-03-30T18:32:20Z", 41 "updated_at": "2017-02-13T05:36:58Z" 42 }, 43 "entity": { 44 "name": "abc-test123", 45 "production": false, 46 "space_guid": "15161161-8b6d-4643-bffb-71569e07f0e9", 47 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 48 "buildpack": null, 49 "detected_buildpack": "Liberty for Java(TM) (WAR, liberty-2016.3.0_0, buildpack-v2.7-20160321-1358, ibmjdk-1.8.0_20160221, env, spring-auto-reconfiguration-1.10.0_RELEASE)", 50 "environment_json": { 51 "redacted_message": "[PRIVATE DATA HIDDEN]" 52 }, 53 "memory": 1024, 54 "instances": 1, 55 "disk_quota": 1024, 56 "state": "STARTED", 57 "version": "f722emccp5-fc16-4b8b-a8ea-e0d44c56a465", 58 "command": null, 59 "console": false, 60 "debug": null, 61 "staging_task_id": "a7808aec96b34e359c47e4320796f221", 62 "package_state": "STAGED", 63 "health_check_type": "port", 64 "health_check_timeout": null, 65 "health_check_http_endpoint": null, 66 "staging_failed_reason": null, 67 "staging_failed_description": null, 68 "diego": true, 69 "docker_image": null, 70 "package_updated_at": "2016-04-07T14:29:33Z", 71 "detected_start_command": ".liberty/initial_startup.rb", 72 "enable_ssh": true, 73 "docker_credentials_json": { 74 "redacted_message": "[PRIVATE DATA HIDDEN]" 75 }, 76 "ports": [ 77 8080 78 ], 79 "space_url": "/v2/spaces/15161161-8b6d-4643-bffb-71569e07f0e9", 80 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 81 "routes_url": "/v2/apps/50a46e93-c9dc-4d85-b76a-4f23c95e7cda/routes", 82 "events_url": "/v2/apps/50a46e93-c9dc-4d85-b76a-4f23c95e7cda/events", 83 "service_bindings_url": "/v2/apps/50a46e93-c9dc-4d85-b76a-4f23c95e7cda/service_bindings", 84 "route_mappings_url": "/v2/apps/50a46e93-c9dc-4d85-b76a-4f23c95e7cda/route_mappings" 85 } 86 }, 87 { 88 "metadata": { 89 "guid": "413a703d-f9f8-4ed1-a350-a45171c6fe60", 90 "url": "/v2/apps/413a703d-f9f8-4ed1-a350-a45171c6fe60", 91 "created_at": "2016-03-30T19:17:13Z", 92 "updated_at": "2017-02-13T05:37:24Z" 93 }, 94 "entity": { 95 "name": "WebSphere-Application-Server-Liberty-at-localhost", 96 "production": false, 97 "space_guid": "15161161-8b6d-4643-bffb-71569e07f0e9", 98 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 99 "buildpack": null, 100 "detected_buildpack": null, 101 "environment_json": { 102 "redacted_message": "[PRIVATE DATA HIDDEN]" 103 }, 104 "memory": 512, 105 "instances": 1, 106 "disk_quota": 1024, 107 "state": "STOPPED", 108 "version": "e3f2189d-c0e7-43fe-9e1b-cbd4ff827eee", 109 "command": null, 110 "console": false, 111 "debug": null, 112 "staging_task_id": null, 113 "package_state": "PENDING", 114 "health_check_type": "port", 115 "health_check_timeout": null, 116 "health_check_http_endpoint": null, 117 "staging_failed_reason": null, 118 "staging_failed_description": null, 119 "diego": true, 120 "docker_image": null, 121 "package_updated_at": null, 122 "detected_start_command": "", 123 "enable_ssh": true, 124 "docker_credentials_json": { 125 "redacted_message": "[PRIVATE DATA HIDDEN]" 126 }, 127 "ports": [ 128 8080 129 ], 130 "space_url": "/v2/spaces/15161161-8b6d-4643-bffb-71569e07f0e9", 131 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 132 "routes_url": "/v2/apps/413a703d-f9f8-4ed1-a350-a45171c6fe60/routes", 133 "events_url": "/v2/apps/413a703d-f9f8-4ed1-a350-a45171c6fe60/events", 134 "service_bindings_url": "/v2/apps/413a703d-f9f8-4ed1-a350-a45171c6fe60/service_bindings", 135 "route_mappings_url": "/v2/apps/413a703d-f9f8-4ed1-a350-a45171c6fe60/route_mappings" 136 } 137 }, 138 { 139 "metadata": { 140 "guid": "c92bc8ea-fc00-4011-ad19-36fbd47a4c30", 141 "url": "/v2/apps/c92bc8ea-fc00-4011-ad19-36fbd47a4c30", 142 "created_at": "2017-05-19T05:31:56Z", 143 "updated_at": "2017-05-19T05:32:41Z" 144 }, 145 "entity": { 146 "name": "testsakshi1051", 147 "production": false, 148 "space_guid": "211b690c-1241-496e-b6ae-e487b7ebe4e8", 149 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 150 "buildpack": "nodejs_buildpack", 151 "detected_buildpack": "", 152 "environment_json": { 153 154 }, 155 "memory": 128, 156 "instances": 2, 157 "disk_quota": 512, 158 "state": "STARTED", 159 "version": "b5658b95-7f69-4f35-91a0-4105a850f134", 160 "command": null, 161 "console": false, 162 "debug": null, 163 "staging_task_id": "15f5c4610e7b4f5fb42aa98c06a7172c", 164 "package_state": "STAGED", 165 "health_check_type": "port", 166 "health_check_timeout": null, 167 "health_check_http_endpoint": null, 168 "staging_failed_reason": null, 169 "staging_failed_description": null, 170 "diego": true, 171 "docker_image": null, 172 "package_updated_at": "2017-05-19T05:32:02Z", 173 "detected_start_command": "npm start", 174 "enable_ssh": true, 175 "docker_credentials_json": { 176 "redacted_message": "[PRIVATE DATA HIDDEN]" 177 }, 178 "ports": [ 179 8080 180 ], 181 "space_url": "/v2/spaces/211b690c-1241-496e-b6ae-e487b7ebe4e8", 182 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 183 "routes_url": "/v2/apps/c92bc8ea-fc00-4011-ad19-36fbd47a4c30/routes", 184 "events_url": "/v2/apps/c92bc8ea-fc00-4011-ad19-36fbd47a4c30/events", 185 "service_bindings_url": "/v2/apps/c92bc8ea-fc00-4011-ad19-36fbd47a4c30/service_bindings", 186 "route_mappings_url": "/v2/apps/c92bc8ea-fc00-4011-ad19-36fbd47a4c30/route_mappings" 187 } 188 } 189 ] 190 }`), 191 ), 192 ) 193 }) 194 195 It("should list all the apps", func() { 196 myapps, err := newApps(server.URL()).List() 197 Expect(err).To(Succeed()) 198 Expect(len(myapps)).To(Equal(3)) 199 app1 := myapps[0] 200 Expect(app1.GUID).To(Equal("50a46e93-c9dc-4d85-b76a-4f23c95e7cda")) 201 Expect(app1.Name).To(Equal("abc-test123")) 202 Expect(app1.SpaceGUID).To(Equal("15161161-8b6d-4643-bffb-71569e07f0e9")) 203 app2 := myapps[1] 204 Expect(app2.GUID).To(Equal("413a703d-f9f8-4ed1-a350-a45171c6fe60")) 205 Expect(app2.Name).To(Equal("WebSphere-Application-Server-Liberty-at-localhost")) 206 Expect(app2.SpaceGUID).To(Equal("15161161-8b6d-4643-bffb-71569e07f0e9")) 207 app3 := myapps[2] 208 Expect(app3.GUID).To(Equal("c92bc8ea-fc00-4011-ad19-36fbd47a4c30")) 209 Expect(app3.Name).To(Equal("testsakshi1051")) 210 Expect(app3.SpaceGUID).To(Equal("211b690c-1241-496e-b6ae-e487b7ebe4e8")) 211 212 }) 213 }) 214 Context("When Server return no apps", func() { 215 BeforeEach(func() { 216 server = ghttp.NewServer() 217 server.AppendHandlers( 218 ghttp.CombineHandlers( 219 ghttp.VerifyRequest(http.MethodGet, "/v2/apps"), 220 ghttp.RespondWith(http.StatusOK, `{ 221 "total_results": 0, 222 "resources": [ 223 ] 224 225 }`), 226 ), 227 ) 228 }) 229 It("should return no apps", func() { 230 myapps, err := newApps(server.URL()).List() 231 Expect(err).To(Succeed()) 232 Expect(len(myapps)).To(Equal(0)) 233 }) 234 235 }) 236 Context("Server return error", func() { 237 BeforeEach(func() { 238 server = ghttp.NewServer() 239 server.SetAllowUnhandledRequests(true) 240 server.AppendHandlers( 241 ghttp.CombineHandlers( 242 ghttp.VerifyRequest(http.MethodGet, "/v2/apps"), 243 ghttp.RespondWith(http.StatusInternalServerError, `{ 244 245 }`), 246 ), 247 ) 248 }) 249 250 It("should return error", func() { 251 myapps, err := newApps(server.URL()).List() 252 Expect(err).To(HaveOccurred()) 253 Expect(myapps).To(BeNil()) 254 }) 255 }) 256 257 }) 258 259 Describe("Create", func() { 260 Context("Create a app", func() { 261 BeforeEach(func() { 262 server = ghttp.NewServer() 263 server.AppendHandlers( 264 ghttp.CombineHandlers( 265 ghttp.VerifyRequest(http.MethodPost, "/v2/apps"), 266 ghttp.VerifyBody([]byte(`{"name":"testapp","memory":128,"instances":2,"disk_quota":512,"space_guid":"211b690c-1241-496e-b6ae-e487b7ebe4e8","buildpack":"nodejs_buildpack"}`)), 267 ghttp.RespondWith(http.StatusCreated, `{ 268 "metadata": { 269 "guid": "18231a23-6056-495f-9ae2-c6c79a15e86c", 270 "url": "/v2/apps/18231a23-6056-495f-9ae2-c6c79a15e86c", 271 "created_at": "2017-05-19T08:31:38Z", 272 "updated_at": null 273 }, 274 "entity": { 275 "name": "testapp", 276 "production": false, 277 "space_guid": "211b690c-1241-496e-b6ae-e487b7ebe4e8", 278 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 279 "buildpack": "nodejs_buildpack", 280 "detected_buildpack": null, 281 "environment_json": { 282 283 }, 284 "memory": 128, 285 "instances": 2, 286 "disk_quota": 512, 287 "state": "STOPPED", 288 "version": "23ba0967-9c2e-4927-9c4a-f5ba2dab6f49", 289 "command": null, 290 "console": false, 291 "debug": null, 292 "staging_task_id": null, 293 "package_state": "PENDING", 294 "health_check_type": "port", 295 "health_check_timeout": null, 296 "health_check_http_endpoint": null, 297 "staging_failed_reason": null, 298 "staging_failed_description": null, 299 "diego": true, 300 "docker_image": null, 301 "package_updated_at": null, 302 "detected_start_command": "", 303 "enable_ssh": true, 304 "docker_credentials_json": { 305 "redacted_message": "[PRIVATE DATA HIDDEN]" 306 }, 307 "ports": [ 308 8080 309 ], 310 "space_url": "/v2/spaces/211b690c-1241-496e-b6ae-e487b7ebe4e8", 311 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 312 "routes_url": "/v2/apps/18231a23-6056-495f-9ae2-c6c79a15e86c/routes", 313 "events_url": "/v2/apps/18231a23-6056-495f-9ae2-c6c79a15e86c/events", 314 "service_bindings_url": "/v2/apps/18231a23-6056-495f-9ae2-c6c79a15e86c/service_bindings", 315 "route_mappings_url": "/v2/apps/18231a23-6056-495f-9ae2-c6c79a15e86c/route_mappings" 316 } 317 }`), 318 ), 319 ) 320 }) 321 322 It("should create the apps", func() { 323 var appPayload = AppRequest{ 324 Name: helpers.String("testapp"), 325 SpaceGUID: helpers.String("211b690c-1241-496e-b6ae-e487b7ebe4e8"), 326 BuildPack: helpers.String("nodejs_buildpack"), 327 Instances: 2, 328 Memory: 128, 329 DiskQuota: 512, 330 } 331 myapp, err := newApps(server.URL()).Create(appPayload) 332 Expect(err).NotTo(HaveOccurred()) 333 Expect(myapp).ShouldNot(BeNil()) 334 Expect(myapp.Metadata.GUID).Should(Equal("18231a23-6056-495f-9ae2-c6c79a15e86c")) 335 Expect(myapp.Entity.Name).Should(Equal("testapp")) 336 Expect(myapp.Entity.SpaceGUID).Should(Equal("211b690c-1241-496e-b6ae-e487b7ebe4e8")) 337 338 }) 339 }) 340 Context("When app creation failed", func() { 341 BeforeEach(func() { 342 server = ghttp.NewServer() 343 server.SetAllowUnhandledRequests(true) 344 server.AppendHandlers( 345 ghttp.CombineHandlers( 346 ghttp.VerifyRequest(http.MethodPost, "/v2/apps"), 347 ghttp.VerifyBody([]byte(`{"name":"testapp","memory":128,"instances":2,"disk_quota":512,"space_guid":"211b690c-1241-496e-b6ae-e487b7ebe4e8","buildpack":"nodejs_buildpack"}`)), 348 ghttp.RespondWith(http.StatusInternalServerError, `Failed to create app`), 349 ), 350 ) 351 }) 352 It("should return error while creating app", func() { 353 var appPayload = AppRequest{ 354 Name: helpers.String("testapp"), 355 SpaceGUID: helpers.String("211b690c-1241-496e-b6ae-e487b7ebe4e8"), 356 BuildPack: helpers.String("nodejs_buildpack"), 357 Instances: 2, 358 Memory: 128, 359 DiskQuota: 512, 360 } 361 myapp, err := newApps(server.URL()).Create(appPayload) 362 Expect(err).To(HaveOccurred()) 363 Expect(myapp).Should(BeNil()) 364 }) 365 366 }) 367 368 Describe("Get", func() { 369 Context("Get a particular app details", func() { 370 BeforeEach(func() { 371 server = ghttp.NewServer() 372 server.AppendHandlers( 373 ghttp.CombineHandlers( 374 ghttp.VerifyRequest(http.MethodGet, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 375 ghttp.RespondWith(http.StatusOK, `{ 376 "metadata": { 377 "guid": "26d673fd-7e64-49b1-9d00-20c0edc9094b", 378 "url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b", 379 "created_at": "2017-05-21T16:00:05Z", 380 "updated_at": "2017-05-21T16:00:49Z" 381 }, 382 "entity": { 383 "name": "testsakshi1051", 384 "production": false, 385 "space_guid": "211b690c-1241-496e-b6ae-e487b7ebe4e8", 386 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 387 "buildpack": "nodejs_buildpack", 388 "detected_buildpack": "", 389 "environment_json": { 390 391 }, 392 "memory": 128, 393 "instances": 2, 394 "disk_quota": 512, 395 "state": "STARTED", 396 "version": "6ba05631-fd78-4f20-9ad8-5cd0b37c000c", 397 "command": null, 398 "console": false, 399 "debug": null, 400 "staging_task_id": "cd4a74fd9e4a443397a688f15920d830", 401 "package_state": "STAGED", 402 "health_check_type": "port", 403 "health_check_timeout": null, 404 "health_check_http_endpoint": null, 405 "staging_failed_reason": null, 406 "staging_failed_description": null, 407 "diego": true, 408 "docker_image": null, 409 "package_updated_at": "2017-05-21T16:00:10Z", 410 "detected_start_command": "npm start", 411 "enable_ssh": true, 412 "docker_credentials_json": { 413 "redacted_message": "[PRIVATE DATA HIDDEN]" 414 }, 415 "ports": [ 416 8080 417 ], 418 "space_url": "/v2/spaces/211b690c-1241-496e-b6ae-e487b7ebe4e8", 419 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 420 "routes_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/routes", 421 "events_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/events", 422 "service_bindings_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/service_bindings", 423 "route_mappings_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/route_mappings" 424 } 425 }`), 426 ), 427 ) 428 }) 429 430 It("should return the details of particular apps", func() { 431 432 myapp, err := newApps(server.URL()).Get("26d673fd-7e64-49b1-9d00-20c0edc9094b") 433 Expect(err).NotTo(HaveOccurred()) 434 Expect(myapp).ShouldNot(BeNil()) 435 Expect(myapp.Metadata.GUID).Should(Equal("26d673fd-7e64-49b1-9d00-20c0edc9094b")) 436 Expect(myapp.Entity.Name).Should(Equal("testsakshi1051")) 437 Expect(myapp.Entity.SpaceGUID).Should(Equal("211b690c-1241-496e-b6ae-e487b7ebe4e8")) 438 439 }) 440 }) 441 Context("When app retrievel failed", func() { 442 BeforeEach(func() { 443 server = ghttp.NewServer() 444 server.SetAllowUnhandledRequests(true) 445 server.AppendHandlers( 446 ghttp.CombineHandlers( 447 ghttp.VerifyRequest(http.MethodGet, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 448 ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve app`), 449 ), 450 ) 451 }) 452 It("should return error while retrieving app", func() { 453 myapp, err := newApps(server.URL()).Get("26d673fd-7e64-49b1-9d00-20c0edc9094b") 454 Expect(err).To(HaveOccurred()) 455 Expect(myapp).Should(BeNil()) 456 }) 457 458 }) 459 460 }) 461 462 Describe("Update", func() { 463 Context("When update of app is successful", func() { 464 BeforeEach(func() { 465 server = ghttp.NewServer() 466 server.AppendHandlers( 467 ghttp.CombineHandlers( 468 ghttp.VerifyRequest(http.MethodPut, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 469 ghttp.VerifyBody([]byte(`{"name":"testappupdate","space_guid":"211b690c-1241-496e-b6ae-e487b7ebe4e8"}`)), 470 ghttp.RespondWith(http.StatusOK, `{ 471 "metadata": { 472 "guid": "26d673fd-7e64-49b1-9d00-20c0edc9094b", 473 "url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b", 474 "created_at": "2017-05-21T16:00:05Z", 475 "updated_at": "2017-05-21T16:01:19Z" 476 }, 477 "entity": { 478 "name": "testappupdate", 479 "production": false, 480 "space_guid": "211b690c-1241-496e-b6ae-e487b7ebe4e8", 481 "stack_guid": "ac91d31a-86a3-453b-babf-8d49c9d763fc", 482 "buildpack": "nodejs_buildpack", 483 "detected_buildpack": "", 484 "environment_json": { 485 486 }, 487 "memory": 128, 488 "instances": 2, 489 "disk_quota": 512, 490 "state": "STARTED", 491 "version": "6ba05631-fd78-4f20-9ad8-5cd0b37c000c", 492 "command": null, 493 "console": false, 494 "debug": null, 495 "staging_task_id": "cd4a74fd9e4a443397a688f15920d830", 496 "package_state": "STAGED", 497 "health_check_type": "port", 498 "health_check_timeout": null, 499 "health_check_http_endpoint": null, 500 "staging_failed_reason": null, 501 "staging_failed_description": null, 502 "diego": true, 503 "docker_image": null, 504 "package_updated_at": "2017-05-21T16:00:10Z", 505 "detected_start_command": "npm start", 506 "enable_ssh": true, 507 "docker_credentials_json": { 508 "redacted_message": "[PRIVATE DATA HIDDEN]" 509 }, 510 "ports": [ 511 8080 512 ], 513 "space_url": "/v2/spaces/211b690c-1241-496e-b6ae-e487b7ebe4e8", 514 "stack_url": "/v2/stacks/ac91d31a-86a3-453b-babf-8d49c9d763fc", 515 "routes_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/routes", 516 "events_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/events", 517 "service_bindings_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/service_bindings", 518 "route_mappings_url": "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b/route_mappings" 519 } 520 }`), 521 ), 522 ) 523 }) 524 525 It("should return app update", func() { 526 var appUpdatePayload = AppRequest{ 527 Name: helpers.String("testappupdate"), 528 SpaceGUID: helpers.String("211b690c-1241-496e-b6ae-e487b7ebe4e8"), 529 } 530 myapp, err := newApps(server.URL()).Update("26d673fd-7e64-49b1-9d00-20c0edc9094b", appUpdatePayload) 531 Expect(err).NotTo(HaveOccurred()) 532 Expect(myapp).ShouldNot(BeNil()) 533 Expect(myapp.Metadata.GUID).Should(Equal("26d673fd-7e64-49b1-9d00-20c0edc9094b")) 534 Expect(myapp.Entity.Name).Should(Equal("testappupdate")) 535 Expect(myapp.Entity.SpaceGUID).Should(Equal("211b690c-1241-496e-b6ae-e487b7ebe4e8")) 536 }) 537 }) 538 Context("When app update is failed", func() { 539 BeforeEach(func() { 540 server = ghttp.NewServer() 541 server.SetAllowUnhandledRequests(true) 542 server.AppendHandlers( 543 ghttp.CombineHandlers( 544 ghttp.VerifyRequest(http.MethodPut, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 545 ghttp.VerifyBody([]byte(`{"name":"testappupdate","space_guid":"211b690c-1241-496e-b6ae-e487b7ebe4e8"}`)), 546 ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve app`), 547 ), 548 ) 549 }) 550 551 It("should return error when app updated", func() { 552 var appUpdatePayload = AppRequest{ 553 Name: helpers.String("testappupdate"), 554 SpaceGUID: helpers.String("211b690c-1241-496e-b6ae-e487b7ebe4e8"), 555 } 556 myapp, err := newApps(server.URL()).Update("26d673fd-7e64-49b1-9d00-20c0edc9094b", appUpdatePayload) 557 Expect(err).To(HaveOccurred()) 558 Expect(myapp).Should(BeNil()) 559 }) 560 }) 561 }) 562 563 Describe("Delete", func() { 564 Context("When delete of app is successful", func() { 565 BeforeEach(func() { 566 server = ghttp.NewServer() 567 server.AppendHandlers( 568 ghttp.CombineHandlers( 569 ghttp.VerifyRequest(http.MethodDelete, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 570 ghttp.RespondWith(http.StatusNoContent, `{}`), 571 ), 572 ) 573 }) 574 575 It("should delete the app", func() { 576 577 err := newApps(server.URL()).Delete("26d673fd-7e64-49b1-9d00-20c0edc9094b", false, false) 578 Expect(err).NotTo(HaveOccurred()) 579 580 }) 581 }) 582 Context("When app delete is failed", func() { 583 BeforeEach(func() { 584 server = ghttp.NewServer() 585 server.SetAllowUnhandledRequests(true) 586 server.AppendHandlers( 587 ghttp.CombineHandlers( 588 ghttp.VerifyRequest(http.MethodDelete, "/v2/apps/26d673fd-7e64-49b1-9d00-20c0edc9094b"), 589 ghttp.RespondWith(http.StatusInternalServerError, `Failed to delete app`), 590 ), 591 ) 592 }) 593 594 It("should return error when app deleted", func() { 595 596 err := newApps(server.URL()).Delete("26d673fd-7e64-49b1-9d00-20c0edc9094b", false, false) 597 Expect(err).To(HaveOccurred()) 598 599 }) 600 }) 601 }) 602 603 }) 604 }) 605 606 func newApps(url string) Apps { 607 608 sess, err := session.New() 609 if err != nil { 610 log.Fatal(err) 611 } 612 conf := sess.Config.Copy() 613 conf.Endpoint = &url 614 client := client.Client{ 615 Config: conf, 616 ServiceName: bluemix.MccpService, 617 } 618 return newAppAPI(&client) 619 }