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