github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/disable_service_access_command_test.go (about) 1 package v6_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 "code.cloudfoundry.org/cli/command/flag" 10 "code.cloudfoundry.org/cli/command/translatableerror" 11 . "code.cloudfoundry.org/cli/command/v6" 12 "code.cloudfoundry.org/cli/command/v6/v6fakes" 13 "code.cloudfoundry.org/cli/util/configv3" 14 "code.cloudfoundry.org/cli/util/ui" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gbytes" 18 ) 19 20 var _ = Describe("disable-service-access Command", func() { 21 var ( 22 cmd DisableServiceAccessCommand 23 testUI *ui.UI 24 fakeConfig *commandfakes.FakeConfig 25 fakeSharedActor *commandfakes.FakeSharedActor 26 fakeActor *v6fakes.FakeDisableServiceAccessActor 27 binaryName string 28 executeErr error 29 extraArgs []string 30 ) 31 32 BeforeEach(func() { 33 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 34 fakeConfig = new(commandfakes.FakeConfig) 35 fakeSharedActor = new(commandfakes.FakeSharedActor) 36 fakeActor = new(v6fakes.FakeDisableServiceAccessActor) 37 extraArgs = nil 38 39 cmd = DisableServiceAccessCommand{ 40 UI: testUI, 41 Config: fakeConfig, 42 SharedActor: fakeSharedActor, 43 Actor: fakeActor, 44 RequiredArgs: flag.Service{ 45 Service: "some-service", 46 }, 47 } 48 49 binaryName = "faceman" 50 fakeConfig.BinaryNameReturns(binaryName) 51 }) 52 53 JustBeforeEach(func() { 54 executeErr = cmd.Execute(extraArgs) 55 }) 56 57 When("the user provides arguments", func() { 58 BeforeEach(func() { 59 extraArgs = []string{"some-extra-arg"} 60 }) 61 62 It("fails with a TooManyArgumentsError", func() { 63 Expect(executeErr).To(MatchError(translatableerror.TooManyArgumentsError{ 64 ExtraArgument: "some-extra-arg", 65 })) 66 }) 67 }) 68 69 When("a cloud controller API endpoint is set", func() { 70 BeforeEach(func() { 71 fakeConfig.TargetReturns("some-url") 72 }) 73 74 When("checking target fails", func() { 75 BeforeEach(func() { 76 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 77 }) 78 79 It("returns a not logged in error", func() { 80 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 81 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 82 }) 83 }) 84 85 When("the user is logged in", func() { 86 BeforeEach(func() { 87 fakeConfig.CurrentUserReturns( 88 configv3.User{Name: "admin"}, 89 nil) 90 fakeSharedActor.IsLoggedInReturns(true) 91 }) 92 93 When("no flags are passed", func() { 94 When("disabling access to the service succeeds", func() { 95 BeforeEach(func() { 96 fakeActor.DisableServiceForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, nil) 97 }) 98 99 It("passes on the service", func() { 100 Expect(fakeActor.DisableServiceForAllOrgsCallCount()).To(Equal(1)) 101 service, _ := fakeActor.DisableServiceForAllOrgsArgsForCall(0) 102 Expect(service).To(Equal("some-service")) 103 }) 104 105 It("displays informative success message", func() { 106 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service for all orgs as admin\\.\\.\\.")) 107 Expect(testUI.Out).To(Say("OK")) 108 }) 109 110 It("returns the warnings", func() { 111 Expect(testUI.Err).To(Say("warning")) 112 Expect(testUI.Err).To(Say("second-warning")) 113 }) 114 }) 115 116 When("disabling access to the service fails", func() { 117 BeforeEach(func() { 118 fakeActor.DisableServiceForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 119 }) 120 121 It("returns the error", func() { 122 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service for all orgs as admin\\.\\.\\.")) 123 Expect(executeErr).To(MatchError("explode")) 124 }) 125 126 It("returns the warnings", func() { 127 Expect(testUI.Err).To(Say("warning")) 128 Expect(testUI.Err).To(Say("second-warning")) 129 }) 130 }) 131 }) 132 133 When("the -p flag is passed", func() { 134 BeforeEach(func() { 135 cmd.ServicePlan = "some-plan" 136 }) 137 138 When("disabling access to the plan succeeds", func() { 139 BeforeEach(func() { 140 fakeActor.DisablePlanForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, nil) 141 }) 142 143 It("passes on the service plan", func() { 144 Expect(fakeActor.DisablePlanForAllOrgsCallCount()).To(Equal(1)) 145 service, plan, _ := fakeActor.DisablePlanForAllOrgsArgsForCall(0) 146 Expect(service).To(Equal("some-service")) 147 Expect(plan).To(Equal("some-plan")) 148 }) 149 150 It("displays an informative success message", func() { 151 Expect(testUI.Out).To(Say("Disabling access of plan some-plan for service some-service as admin\\.\\.\\.")) 152 Expect(testUI.Out).To(Say("OK")) 153 }) 154 155 It("returns the warnings", func() { 156 Expect(testUI.Err).To(Say("warning")) 157 Expect(testUI.Err).To(Say("second-warning")) 158 }) 159 }) 160 161 When("disabling access to the plan fails", func() { 162 BeforeEach(func() { 163 fakeActor.DisablePlanForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 164 }) 165 166 It("returns the error", func() { 167 Expect(testUI.Out).To(Say("Disabling access of plan some-plan for service some-service as admin\\.\\.\\.")) 168 Expect(executeErr).To(MatchError("explode")) 169 }) 170 171 It("returns the warnings", func() { 172 Expect(testUI.Err).To(Say("warning")) 173 Expect(testUI.Err).To(Say("second-warning")) 174 }) 175 }) 176 }) 177 178 When("the -b flag is passed", func() { 179 BeforeEach(func() { 180 cmd.ServiceBroker = "some-broker" 181 }) 182 183 When("disabling access for the broker succeeds", func() { 184 BeforeEach(func() { 185 fakeActor.DisableServiceForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, nil) 186 }) 187 188 It("passes on the service broker", func() { 189 Expect(fakeActor.DisableServiceForAllOrgsCallCount()).To(Equal(1)) 190 service, broker := fakeActor.DisableServiceForAllOrgsArgsForCall(0) 191 Expect(service).To(Equal("some-service")) 192 Expect(broker).To(Equal("some-broker")) 193 }) 194 195 It("displays an informative success message", func() { 196 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service from broker some-broker for all orgs as admin\\.\\.\\.")) 197 Expect(testUI.Out).To(Say("OK")) 198 }) 199 200 It("returns the warnings", func() { 201 Expect(testUI.Err).To(Say("warning")) 202 Expect(testUI.Err).To(Say("second-warning")) 203 }) 204 }) 205 206 When("disabling access to the broker fails", func() { 207 BeforeEach(func() { 208 fakeActor.DisableServiceForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("oops")) 209 }) 210 211 It("returns the error", func() { 212 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service from broker some-broker for all orgs as admin\\.\\.\\.")) 213 Expect(executeErr).To(MatchError("oops")) 214 }) 215 216 It("returns the warnings", func() { 217 Expect(testUI.Err).To(Say("warning")) 218 Expect(testUI.Err).To(Say("second-warning")) 219 }) 220 }) 221 }) 222 223 When("the -o flag is passed", func() { 224 BeforeEach(func() { 225 cmd.Organization = "some-org" 226 }) 227 228 When("disabling access to the org succeeds", func() { 229 BeforeEach(func() { 230 fakeActor.DisableServiceForOrgReturns(v2action.Warnings{"warning", "second-warning"}, nil) 231 }) 232 233 It("passes on the organization name", func() { 234 Expect(fakeActor.DisableServiceForOrgCallCount()).To(Equal(1)) 235 service, org, _ := fakeActor.DisableServiceForOrgArgsForCall(0) 236 Expect(service).To(Equal("some-service")) 237 Expect(org).To(Equal("some-org")) 238 }) 239 240 It("displays an informative success message", func() { 241 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service for the org some-org as admin...")) 242 Expect(testUI.Out).To(Say("OK")) 243 }) 244 245 It("returns the warnings", func() { 246 Expect(testUI.Err).To(Say("warning")) 247 Expect(testUI.Err).To(Say("second-warning")) 248 }) 249 }) 250 251 When("disabling access to the org fails", func() { 252 BeforeEach(func() { 253 fakeActor.DisableServiceForOrgReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 254 }) 255 256 It("returns the error", func() { 257 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service for the org some-org as admin...")) 258 Expect(executeErr).To(MatchError("explode")) 259 }) 260 261 It("returns the warnings", func() { 262 Expect(testUI.Err).To(Say("warning")) 263 Expect(testUI.Err).To(Say("second-warning")) 264 }) 265 }) 266 }) 267 268 When("the -p and -o flags are passed", func() { 269 BeforeEach(func() { 270 cmd.Organization = "some-org" 271 cmd.ServicePlan = "some-plan" 272 }) 273 274 When("disabling access to the plan in the org succeeds", func() { 275 BeforeEach(func() { 276 fakeActor.DisablePlanForOrgReturns(v2action.Warnings{"warning", "second-warning"}, nil) 277 }) 278 279 It("passes on the plan and organization name", func() { 280 Expect(fakeActor.DisablePlanForOrgCallCount()).To(Equal(1)) 281 service, plan, org, _ := fakeActor.DisablePlanForOrgArgsForCall(0) 282 283 Expect(service).To(Equal("some-service")) 284 Expect(plan).To(Equal("some-plan")) 285 Expect(org).To(Equal("some-org")) 286 }) 287 288 It("displays an informative success message", func() { 289 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service for org some-org as admin...")) 290 Expect(testUI.Out).To(Say("OK")) 291 }) 292 293 It("returns the warnings", func() { 294 Expect(testUI.Err).To(Say("warning")) 295 Expect(testUI.Err).To(Say("second-warning")) 296 }) 297 }) 298 299 When("disabling access to the plan in the org fails", func() { 300 BeforeEach(func() { 301 fakeActor.DisablePlanForOrgReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 302 }) 303 304 It("returns the error", func() { 305 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service for org some-org as admin...")) 306 Expect(executeErr).To(MatchError("explode")) 307 }) 308 309 It("returns the warnings", func() { 310 Expect(testUI.Err).To(Say("warning")) 311 Expect(testUI.Err).To(Say("second-warning")) 312 }) 313 }) 314 }) 315 316 When("the -b and -p flags are passed", func() { 317 BeforeEach(func() { 318 cmd.ServiceBroker = "some-broker" 319 cmd.ServicePlan = "some-plan" 320 }) 321 322 When("disabling access to the plan from the broker succeeds", func() { 323 BeforeEach(func() { 324 fakeActor.DisablePlanForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, nil) 325 }) 326 327 It("passes on the plan, service and broker name", func() { 328 Expect(fakeActor.DisablePlanForAllOrgsCallCount()).To(Equal(1)) 329 service, plan, broker := fakeActor.DisablePlanForAllOrgsArgsForCall(0) 330 331 Expect(broker).To(Equal("some-broker")) 332 Expect(service).To(Equal("some-service")) 333 Expect(plan).To(Equal("some-plan")) 334 }) 335 336 It("displays an informative success message", func() { 337 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service from broker some-broker for all orgs as admin...")) 338 Expect(testUI.Out).To(Say("OK")) 339 }) 340 341 It("returns the warnings", func() { 342 Expect(testUI.Err).To(Say("warning")) 343 Expect(testUI.Err).To(Say("second-warning")) 344 }) 345 }) 346 347 When("disabling access to the plan in the org fails", func() { 348 BeforeEach(func() { 349 fakeActor.DisablePlanForAllOrgsReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 350 }) 351 352 It("returns the error", func() { 353 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service from broker some-broker for all orgs as admin...")) 354 Expect(executeErr).To(MatchError("explode")) 355 }) 356 357 It("returns the warnings", func() { 358 Expect(testUI.Err).To(Say("warning")) 359 Expect(testUI.Err).To(Say("second-warning")) 360 }) 361 }) 362 }) 363 364 When("the -b and -o flags are passed", func() { 365 BeforeEach(func() { 366 cmd.ServiceBroker = "some-broker" 367 cmd.Organization = "some-org" 368 }) 369 370 When("disabling access to the service from the broker in the org succeeds", func() { 371 BeforeEach(func() { 372 fakeActor.DisableServiceForOrgReturns(v2action.Warnings{"warning", "second-warning"}, nil) 373 }) 374 375 It("passes on the service name, broker name and org name", func() { 376 Expect(fakeActor.DisableServiceForOrgCallCount()).To(Equal(1)) 377 service, org, broker := fakeActor.DisableServiceForOrgArgsForCall(0) 378 379 Expect(service).To(Equal("some-service")) 380 Expect(org).To(Equal("some-org")) 381 Expect(broker).To(Equal("some-broker")) 382 }) 383 384 It("displays an informative success message", func() { 385 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service from broker some-broker for the org some-org as admin...")) 386 Expect(testUI.Out).To(Say("OK")) 387 }) 388 389 It("returns the warnings", func() { 390 Expect(testUI.Err).To(Say("warning")) 391 Expect(testUI.Err).To(Say("second-warning")) 392 }) 393 }) 394 395 When("disabling access to the service from the broker in the org fails", func() { 396 BeforeEach(func() { 397 fakeActor.DisableServiceForOrgReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 398 }) 399 400 It("returns the error", func() { 401 Expect(testUI.Out).To(Say("Disabling access to all plans of service some-service from broker some-broker for the org some-org as admin...")) 402 Expect(executeErr).To(MatchError("explode")) 403 }) 404 405 It("returns the warnings", func() { 406 Expect(testUI.Err).To(Say("warning")) 407 Expect(testUI.Err).To(Say("second-warning")) 408 }) 409 }) 410 }) 411 412 When("the -b, -o and -p flags are passed", func() { 413 BeforeEach(func() { 414 cmd.ServiceBroker = "some-broker" 415 cmd.Organization = "some-org" 416 cmd.ServicePlan = "some-plan" 417 }) 418 419 When("disabling access to the plan of the service from the broker in the org succeeds", func() { 420 BeforeEach(func() { 421 fakeActor.DisablePlanForOrgReturns(v2action.Warnings{"warning", "second-warning"}, nil) 422 }) 423 424 It("passes on the service name, plan name, broker name and org name", func() { 425 Expect(fakeActor.DisablePlanForOrgCallCount()).To(Equal(1)) 426 service, plan, org, broker := fakeActor.DisablePlanForOrgArgsForCall(0) 427 428 Expect(service).To(Equal("some-service")) 429 Expect(plan).To(Equal("some-plan")) 430 Expect(org).To(Equal("some-org")) 431 Expect(broker).To(Equal("some-broker")) 432 }) 433 434 It("displays an informative success message", func() { 435 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service from broker some-broker for org some-org as admin...")) 436 Expect(testUI.Out).To(Say("OK")) 437 }) 438 439 It("returns the warnings", func() { 440 Expect(testUI.Err).To(Say("warning")) 441 Expect(testUI.Err).To(Say("second-warning")) 442 }) 443 }) 444 445 When("disabling access to the plan of the service from the broker in the org fails", func() { 446 BeforeEach(func() { 447 fakeActor.DisablePlanForOrgReturns(v2action.Warnings{"warning", "second-warning"}, errors.New("explode")) 448 }) 449 450 It("returns the error", func() { 451 Expect(testUI.Out).To(Say("Disabling access to plan some-plan of service some-service from broker some-broker for org some-org as admin...")) 452 Expect(executeErr).To(MatchError("explode")) 453 }) 454 455 It("returns the warnings", func() { 456 Expect(testUI.Err).To(Say("warning")) 457 Expect(testUI.Err).To(Say("second-warning")) 458 }) 459 }) 460 }) 461 }) 462 }) 463 })