github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/shared/isolated/enable_service_access_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("enable service access command", func() { 14 Describe("help", func() { 15 When("--help flag is set", func() { 16 It("displays command usage to output", func() { 17 session := helpers.CF("enable-service-access", "--help") 18 Eventually(session).Should(Say("NAME:")) 19 Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs")) 20 Eventually(session).Should(Say("USAGE:")) 21 Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 22 Eventually(session).Should(Say("OPTIONS:")) 23 Eventually(session).Should(Say("\\s+\\-b\\s+Enable access to a service from a particular service broker. Required when service name is ambiguous")) 24 Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization")) 25 Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan")) 26 Eventually(session).Should(Say("SEE ALSO:")) 27 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 28 Eventually(session).Should(Exit(0)) 29 }) 30 }) 31 32 When("no service argument was provided", func() { 33 It("displays a warning, the help text, and exits 1", func() { 34 session := helpers.CF("enable-service-access") 35 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 36 Eventually(session).Should(Say("NAME:")) 37 Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs")) 38 Eventually(session).Should(Say("USAGE:")) 39 Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 40 Eventually(session).Should(Say("OPTIONS:")) 41 Eventually(session).Should(Say("\\s+\\-b\\s+Enable access to a service from a particular service broker. Required when service name is ambiguous")) 42 Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization")) 43 Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan")) 44 Eventually(session).Should(Say("SEE ALSO:")) 45 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 46 Eventually(session).Should(Exit(1)) 47 }) 48 }) 49 50 When("two services arguments are provided", func() { 51 It("displays an error, and exits 1", func() { 52 session := helpers.CF("enable-service-access", "a-service", "another-service") 53 Eventually(session).Should(Say("FAILED")) 54 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "another-service"`)) 55 Eventually(session).Should(Say("NAME:")) 56 Eventually(session).Should(Say("\\s+enable-service-access - Enable access to a service or service plan for one or all orgs")) 57 Eventually(session).Should(Say("USAGE:")) 58 Eventually(session).Should(Say("\\s+cf enable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 59 Eventually(session).Should(Say("OPTIONS:")) 60 Eventually(session).Should(Say("\\s+\\-b\\s+Enable access to a service from a particular service broker. Required when service name is ambiguous")) 61 Eventually(session).Should(Say("\\s+\\-o\\s+Enable access for a specified organization")) 62 Eventually(session).Should(Say("\\s+\\-p\\s+Enable access to a specified service plan")) 63 Eventually(session).Should(Say("SEE ALSO:")) 64 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 65 Eventually(session).Should(Exit(1)) 66 }) 67 }) 68 }) 69 70 Context("not logged in", func() { 71 BeforeEach(func() { 72 helpers.LogoutCF() 73 }) 74 75 It("displays FAILED, an informative error message, and exits 1", func() { 76 session := helpers.CF("enable-service-access", "does-not-matter") 77 Eventually(session).Should(Say("FAILED")) 78 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in.")) 79 Eventually(session).Should(Exit(1)) 80 }) 81 }) 82 83 Context("logged in", func() { 84 var username string 85 BeforeEach(func() { 86 username, _ = helpers.GetCredentials() 87 helpers.LoginCF() 88 }) 89 90 Context("the service does not exist", func() { 91 When("only the service is specified", func() { 92 It("displays FAILED, an informative error message, and exits 1", func() { 93 session := helpers.CF("enable-service-access", "some-service") 94 Eventually(session).Should(Say("Enabling access to all plans of service some-service for all orgs as %s\\.\\.\\.", username)) 95 Eventually(session).Should(Say("FAILED")) 96 Eventually(session.Err).Should(Say("Service offering 'some-service' not found")) 97 Eventually(session).Should(Exit(1)) 98 }) 99 }) 100 101 When("a service and an org are specified", func() { 102 It("displays FAILED, an informative error message, and exits 1", func() { 103 session := helpers.CF("enable-service-access", "some-service", "-o", "some-org") 104 Eventually(session).Should(Say("Enabling access to all plans of service some-service for the org some-org as %s\\.\\.\\.", username)) 105 Eventually(session).Should(Say("FAILED")) 106 Eventually(session.Err).Should(Say("Service offering 'some-service' not found")) 107 Eventually(session).Should(Exit(1)) 108 }) 109 }) 110 111 When("a service and a plan are specified", func() { 112 It("displays FAILED, an informative error message, and exits 1", func() { 113 session := helpers.CF("enable-service-access", "some-service", "-p", "some-plan") 114 Eventually(session).Should(Say("Enabling access of plan some-plan for service some-service as %s\\.\\.\\.", username)) 115 Eventually(session).Should(Say("FAILED")) 116 Eventually(session.Err).Should(Say("Service offering 'some-service' not found")) 117 Eventually(session).Should(Exit(1)) 118 }) 119 }) 120 121 When("a service, a plan and an org are specified", func() { 122 It("displays FAILED, an informative error message, and exits 1", func() { 123 session := helpers.CF("enable-service-access", "some-service", "-p", "some-plan", "-o", "some-org") 124 Eventually(session).Should(Say("Enabling access to plan some-plan of service some-service for org some-org as %s\\.\\.\\.", username)) 125 Eventually(session).Should(Say("FAILED")) 126 Eventually(session.Err).Should(Say("Service offering 'some-service' not found")) 127 Eventually(session).Should(Exit(1)) 128 }) 129 }) 130 }) 131 132 Context("a service broker is registered", func() { 133 var ( 134 orgName string 135 spaceName string 136 service string 137 servicePlan string 138 broker *fakeservicebroker.FakeServiceBroker 139 secondBroker *fakeservicebroker.FakeServiceBroker 140 ) 141 142 BeforeEach(func() { 143 orgName = helpers.NewOrgName() 144 spaceName = helpers.NewSpaceName() 145 helpers.SetupCF(orgName, spaceName) 146 147 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 148 service = broker.ServiceName() 149 servicePlan = broker.ServicePlanName() 150 }) 151 152 AfterEach(func() { 153 broker.Destroy() 154 helpers.QuickDeleteOrg(orgName) 155 }) 156 157 When("a service name is provided", func() { 158 It("displays an informative message, exits 0, and enables the service for all orgs", func() { 159 session := helpers.CF("enable-service-access", service) 160 Eventually(session).Should(Say("Enabling access to all plans of service %s for all orgs as %s...", service, username)) 161 Eventually(session).Should(Say("OK")) 162 Eventually(session).Should(Exit(0)) 163 164 session = helpers.CF("service-access", "-e", service) 165 Eventually(session).Should(Exit(0)) 166 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 167 Eventually(session).Should(Say("%s\\s+%s\\s+all", 168 service, 169 servicePlan, 170 )) 171 }) 172 173 When("service is already enabled for an org for a plan", func() { 174 BeforeEach(func() { 175 session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", orgName) 176 Eventually(session).Should(Say("OK")) 177 Eventually(session).Should(Exit(0)) 178 }) 179 180 It("disables the limited access for that org", func() { 181 session := helpers.CF("enable-service-access", service, "-p", servicePlan) 182 Eventually(session).Should(Say("Enabling access of plan %s for service %s as %s...", servicePlan, service, username)) 183 Eventually(session).Should(Say("OK")) 184 Eventually(session).Should(Exit(0)) 185 186 session = helpers.CF("service-access", "-e", service) 187 Eventually(session).Should(Exit(0)) 188 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 189 Eventually(session).Should(Say("%s\\s+%s\\s+all\\s", 190 service, 191 servicePlan, 192 )) 193 194 }) 195 196 When("enabling access globally", func() { 197 It("should disbale org level access first", func() { 198 session := helpers.CF("enable-service-access", service) 199 Eventually(session).Should(Say("OK")) 200 Eventually(session).Should(Exit(0)) 201 202 session = helpers.CF("service-access", "-e", service) 203 Eventually(session).Should(Exit(0)) 204 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 205 Eventually(session).Should(Say("%s\\s+%s\\s+all", 206 service, 207 servicePlan, 208 )) 209 Consistently(session).ShouldNot(Say(orgName)) 210 }) 211 }) 212 }) 213 }) 214 215 When("two services with the same name are registered", func() { 216 BeforeEach(func() { 217 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 218 secondBroker = fakeservicebroker.NewAlternate() 219 secondBroker.Services[0].Name = service 220 secondBroker.Services[0].Plans[0].Name = servicePlan 221 secondBroker.EnsureBrokerIsAvailable() 222 }) 223 224 AfterEach(func() { 225 secondBroker.Destroy() 226 }) 227 228 When("a service name and broker name are provided", func() { 229 It("displays an informative message, exits 0, and enables access to the service", func() { 230 session := helpers.CF("enable-service-access", service, "-b", secondBroker.Name()) 231 Eventually(session).Should(Say("Enabling access to all plans of service %s from broker %s for all orgs as %s...", service, secondBroker.Name(), username)) 232 Eventually(session).Should(Say("OK")) 233 Eventually(session).Should(Exit(0)) 234 235 session = helpers.CF("service-access", "-b", secondBroker.Name()) 236 Eventually(session).Should(Exit(0)) 237 Eventually(session).Should(Say("broker:\\s+%s", secondBroker.Name())) 238 Eventually(session).Should(Say("%s\\s+%s\\s+all", 239 service, 240 servicePlan, 241 )) 242 }) 243 244 When("a broker name is not provided", func() { 245 It("fails to create the service", func() { 246 session := helpers.CF("enable-service-access", service) 247 Eventually(session).Should(Say("Enabling access to all plans of service %s for all orgs as %s...", service, username)) 248 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers. Specify a broker by using the '-b' flag.", service)) 249 Eventually(session).Should(Say("FAILED")) 250 Eventually(session).Should(Exit(1)) 251 252 session = helpers.CF("service-access", "-b", secondBroker.Name()) 253 Eventually(session).Should(Exit(0)) 254 Eventually(session).Should(Say("broker:\\s+%s", secondBroker.Name())) 255 Eventually(session).Should(Say("%s\\s+%s\\s+none", 256 service, 257 servicePlan, 258 )) 259 }) 260 }) 261 262 When("no broker by that name exists", func() { 263 It("displays an informative message, exits 1", func() { 264 session := helpers.CF("enable-service-access", service, "-b", "non-existent-broker") 265 Eventually(session).Should(Say("Enabling access to all plans of service %s from broker %s for all orgs as %s...", service, "non-existent-broker", username)) 266 Eventually(session.Err).Should(Say("Service broker 'non-existent-broker' not found")) 267 Eventually(session.Err).Should(Say("TIP: Use 'cf service-brokers' to see a list of available brokers.")) 268 Eventually(session).Should(Say("FAILED")) 269 Eventually(session).Should(Exit(1)) 270 }) 271 }) 272 }) 273 }) 274 275 When("a service name and plan name are provided", func() { 276 It("displays an informative message, exits 0, and enables the plan for all orgs", func() { 277 session := helpers.CF("enable-service-access", service, "-p", servicePlan) 278 Eventually(session).Should(Say("Enabling access of plan %s for service %s as %s...", servicePlan, service, username)) 279 Eventually(session).Should(Say("OK")) 280 Eventually(session).Should(Exit(0)) 281 282 session = helpers.CF("service-access", "-e", service) 283 Eventually(session).Should(Exit(0)) 284 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 285 Eventually(session).Should(Say("%s\\s+%s\\s+all", 286 service, 287 servicePlan, 288 )) 289 }) 290 }) 291 292 When("a service name and org is provided", func() { 293 It("displays an informative message, and exits 0", func() { 294 session := helpers.CF("enable-service-access", service, "-o", orgName) 295 Eventually(session).Should(Say("Enabling access to all plans of service %s for the org %s as %s...", service, orgName, username)) 296 Eventually(session).Should(Say("OK")) 297 Eventually(session).Should(Exit(0)) 298 }) 299 }) 300 301 When("a service name, plan name and org is provided", func() { 302 It("displays an informative message, and exits 0", func() { 303 session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", orgName) 304 Eventually(session).Should(Say("Enabling access to plan %s of service %s for org %s as %s...", servicePlan, service, orgName, username)) 305 Eventually(session).Should(Say("OK")) 306 Eventually(session).Should(Exit(0)) 307 308 session = helpers.CF("service-access", "-e", service) 309 Eventually(session).Should(Exit(0)) 310 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 311 Eventually(session).Should(Say("%s\\s+%s\\s+%s\\s+%s", 312 service, 313 servicePlan, 314 "limited", 315 orgName, 316 )) 317 }) 318 }) 319 320 When("the org does not exist", func() { 321 It("displays FAILED, an informative error message, and exits 1", func() { 322 session := helpers.CF("enable-service-access", service, "-o", "not-a-real-org") 323 Eventually(session).Should(Say("Enabling access to all plans of service %s for the org not-a-real-org as %s...", service, username)) 324 Eventually(session).Should(Say("FAILED")) 325 Eventually(session.Err).Should(Say("Organization 'not-a-real-org' not found")) 326 Eventually(session).Should(Exit(1)) 327 }) 328 }) 329 330 When("the plan does not exist", func() { 331 It("displays FAILED, an informative error message, and exits 1", func() { 332 session := helpers.CF("enable-service-access", service, "-p", "plan-does-not-exist") 333 Eventually(session).Should(Say("Enabling access of plan plan-does-not-exist for service %s as %s...", service, username)) 334 Eventually(session).Should(Say("FAILED")) 335 Eventually(session.Err).Should(Say("The plan plan-does-not-exist could not be found for service %s", service)) 336 Eventually(session).Should(Exit(1)) 337 }) 338 }) 339 340 When("the plan does exist and the org does not exist", func() { 341 It("displays FAILED, an informative error message, and exits 1", func() { 342 session := helpers.CF("enable-service-access", service, "-p", servicePlan, "-o", "not-a-real-org") 343 Eventually(session).Should(Say("Enabling access to plan %s of service %s for org not-a-real-org as %s...", servicePlan, service, username)) 344 Eventually(session).Should(Say("FAILED")) 345 Eventually(session.Err).Should(Say("Organization 'not-a-real-org' not found")) 346 Eventually(session).Should(Exit(1)) 347 }) 348 }) 349 350 When("the plan does not exist and the org does exist", func() { 351 It("displays FAILED, an informative error message, and exits 1", func() { 352 session := helpers.CF("enable-service-access", service, "-p", "not-a-real-plan", "-o", orgName) 353 Eventually(session).Should(Say("Enabling access to plan not-a-real-plan of service %s for org %s as %s...", service, orgName, username)) 354 Eventually(session).Should(Say("FAILED")) 355 Eventually(session.Err).Should(Say("Service plan 'not-a-real-plan' not found")) 356 Eventually(session).Should(Exit(1)) 357 }) 358 }) 359 360 Context("when access is already enabled in the org", func() { 361 BeforeEach(func() { 362 session := helpers.CF("enable-service-access", service, "-o", orgName) 363 Eventually(session).Should(Say("OK")) 364 }) 365 366 It("displays OK, and exits 0", func() { 367 session := helpers.CF("enable-service-access", service, "-o", orgName) 368 Eventually(session).Should(Say("Enabling access to all plans of service %s for the org %s as %s...", service, orgName, username)) 369 Eventually(session).Should(Say("OK")) 370 Eventually(session).Should(Exit(0)) 371 }) 372 }) 373 374 Context("when access is already globally enabled", func() { 375 BeforeEach(func() { 376 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 377 }) 378 379 When("when we try to enable access for an org", func() { 380 It("should still be enabled only globally", func() { 381 session := helpers.CF("enable-service-access", service, "-o", orgName) 382 Eventually(session).Should(Say("OK")) 383 Eventually(session).Should(Exit(0)) 384 385 session = helpers.CF("service-access", "-e", service) 386 Eventually(session).Should(Exit(0)) 387 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 388 Eventually(session).Should(Say("%s\\s+%s\\s+all", 389 service, 390 servicePlan, 391 )) 392 Consistently(session).ShouldNot(Say(orgName)) 393 394 }) 395 }) 396 397 When("when we try to enable access for an org for a plan", func() { 398 It("should still be enabled only globally", func() { 399 session := helpers.CF("enable-service-access", service, "-o", orgName, "-p", servicePlan) 400 Eventually(session).Should(Say("OK")) 401 Eventually(session).Should(Exit(0)) 402 403 session = helpers.CF("service-access", "-e", service) 404 Eventually(session).Should(Exit(0)) 405 Eventually(session).Should(Say("broker:\\s+%s", broker.Name())) 406 Eventually(session).Should(Say("%s\\s+%s\\s+all", 407 service, 408 servicePlan, 409 )) 410 Consistently(session).ShouldNot(Say(orgName)) 411 }) 412 }) 413 414 When("the service already has access globally enabled", func() { 415 It("displays an informative message, and exits 0", func() { 416 session := helpers.CF("enable-service-access", service) 417 Eventually(session).Should(Say("Enabling access to all plans of service %s for all orgs as %s...", service, username)) 418 Eventually(session).Should(Say("OK")) 419 Eventually(session).Should(Exit(0)) 420 }) 421 }) 422 423 When("the plan already has access globally enabled", func() { 424 It("displays an informative message, and exits 0", func() { 425 session := helpers.CF("enable-service-access", service, "-p", servicePlan) 426 Eventually(session).Should(Say("Enabling access of plan %s for service %s as %s...", servicePlan, service, username)) 427 Eventually(session).Should(Say("OK")) 428 Eventually(session).Should(Exit(0)) 429 }) 430 }) 431 }) 432 }) 433 }) 434 })