github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/marketplace_command_test.go (about) 1 package isolated 2 3 import ( 4 "strings" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/integration/helpers" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("marketplace command", func() { 16 Describe("help", func() { 17 When("the --help flag is set", func() { 18 It("displays command usage to output", func() { 19 session := helpers.CF("marketplace", "--help") 20 Eventually(session).Should(Say("NAME:")) 21 Eventually(session).Should(Say("marketplace - List available offerings in the marketplace")) 22 Eventually(session).Should(Say("USAGE:")) 23 Eventually(session).Should(Say("cf marketplace \\[-s SERVICE\\] \\[--no-plans\\]")) 24 Eventually(session).Should(Say("ALIAS:")) 25 Eventually(session).Should(Say("m")) 26 Eventually(session).Should(Say("OPTIONS:")) 27 Eventually(session).Should(Say("-s\\s+Show plan details for a particular service offering")) 28 Eventually(session).Should(Say("--no-plans\\s+Hide plan information for service offerings")) 29 Eventually(session).Should(Say("create-service, services")) 30 Eventually(session).Should(Exit(0)) 31 }) 32 }) 33 }) 34 35 When("no flags are passed", func() { 36 When("an API target is not set", func() { 37 BeforeEach(func() { 38 helpers.UnsetAPI() 39 }) 40 41 It("displays an error message that no API endpoint is set", func() { 42 session := helpers.CF("marketplace") 43 Eventually(session).Should(Say("FAILED")) 44 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 45 Eventually(session).Should(Exit(1)) 46 }) 47 }) 48 49 When("an API endpoint is set", func() { 50 When("not logged in", func() { 51 When("there are accessible services", func() { 52 var ( 53 broker1 helpers.ServiceBroker 54 broker2 helpers.ServiceBroker 55 org string 56 space string 57 ) 58 59 BeforeEach(func() { 60 org = helpers.NewOrgName() 61 space = helpers.NewSpaceName() 62 helpers.SetupCF(org, space) 63 helpers.TargetOrgAndSpace(org, space) 64 65 domain := helpers.DefaultSharedDomain() 66 67 broker1 = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE-1"), "SERVICE-PLAN-1") 68 enableServiceAccess(broker1) 69 broker2 = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE-2"), "SERVICE-PLAN-2") 70 enableServiceAccess(broker2) 71 72 helpers.LogoutCF() 73 }) 74 75 AfterEach(func() { 76 helpers.SetupCF(org, space) 77 broker1.Destroy() 78 broker2.Destroy() 79 helpers.QuickDeleteOrg(org) 80 }) 81 82 It("displays a table of all available services and a tip", func() { 83 session := helpers.CF("marketplace") 84 Eventually(session).Should(Say("Getting all services from marketplace")) 85 Eventually(session).Should(Say("OK")) 86 Eventually(session).Should(Say("\n\n")) 87 Eventually(session).Should(Say("service\\s+plans\\s+description")) 88 Eventually(session).Should(Say("%s\\s+%s\\s+fake service", getServiceName(broker1), getBrokerPlanNames(broker1))) 89 Eventually(session).Should(Say("%s\\s+%s\\s+fake service", getServiceName(broker2), getBrokerPlanNames(broker2))) 90 Eventually(session).Should(Say("TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.")) 91 Eventually(session).Should(Exit(0)) 92 }) 93 }) 94 }) 95 96 When("logged in", func() { 97 var user string 98 99 BeforeEach(func() { 100 helpers.LoginCF() 101 user, _ = helpers.GetCredentials() 102 }) 103 104 When("no space is targeted", func() { 105 BeforeEach(func() { 106 helpers.TargetOrg(ReadOnlyOrg) 107 }) 108 109 It("displays an error that a space must be targeted", func() { 110 session := helpers.CF("marketplace") 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("Cannot list marketplace services without a targeted space")) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 117 When("a service is accessible but not in the currently targeted org", func() { 118 var ( 119 broker1 helpers.ServiceBroker 120 org1, space1 string 121 122 broker2 helpers.ServiceBroker 123 org2, space2 string 124 ) 125 126 BeforeEach(func() { 127 org1 = helpers.NewOrgName() 128 space1 = helpers.NewSpaceName() 129 helpers.SetupCF(org1, space1) 130 helpers.TargetOrgAndSpace(org1, space1) 131 132 domain := helpers.DefaultSharedDomain() 133 134 broker1 = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE-1"), "SERVICE-PLAN-1") 135 enableServiceAccessForOrg(broker1, org1) 136 137 org2 = helpers.NewOrgName() 138 space2 = helpers.NewSpaceName() 139 helpers.CreateOrgAndSpace(org2, space2) 140 helpers.TargetOrgAndSpace(org2, space2) 141 142 broker2 = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE-2"), "SERVICE-PLAN-2") 143 enableServiceAccess(broker2) 144 }) 145 146 AfterEach(func() { 147 helpers.TargetOrgAndSpace(org2, space2) 148 broker2.Destroy() 149 helpers.QuickDeleteOrg(org2) 150 151 helpers.TargetOrgAndSpace(org1, space1) 152 broker1.Destroy() 153 helpers.QuickDeleteOrg(org1) 154 }) 155 156 When("CC API does not return broker names in response", func() { 157 BeforeEach(func() { 158 helpers.SkipIfVersionAtLeast(ccversion.MinVersionMultiServiceRegistrationV2) 159 }) 160 161 It("displays a table and tip that does not include that service", func() { 162 session := helpers.CF("marketplace") 163 Eventually(session).Should(Say("Getting services from marketplace in org %s / space %s as %s\\.\\.\\.", org2, space2, user)) 164 Eventually(session).Should(Say("OK")) 165 Eventually(session).Should(Say("\n\n")) 166 Eventually(session).Should(Say("service\\s+plans\\s+description\\s+broker")) 167 Consistently(session).ShouldNot(Say(getServiceName(broker1))) 168 Consistently(session).ShouldNot(Say(getBrokerPlanNames(broker1))) 169 Eventually(session).Should(Say("%s\\s+%s\\s+fake service\\s*", getServiceName(broker2), getBrokerPlanNames(broker2))) 170 Eventually(session).Should(Say("TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.")) 171 Eventually(session).Should(Exit(0)) 172 }) 173 }) 174 175 When("CC API returns broker names in response", func() { 176 BeforeEach(func() { 177 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 178 }) 179 180 It("displays a table with broker name", func() { 181 session := helpers.CF("marketplace") 182 Eventually(session).Should(Say("Getting services from marketplace in org %s / space %s as %s\\.\\.\\.", org2, space2, user)) 183 Eventually(session).Should(Say("OK")) 184 Eventually(session).Should(Say("\n\n")) 185 Eventually(session).Should(Say("service\\s+plans\\s+description\\s+broker")) 186 Consistently(session).ShouldNot(Say(getServiceName(broker1))) 187 Consistently(session).ShouldNot(Say(getBrokerPlanNames(broker1))) 188 Consistently(session).ShouldNot(Say(broker1.Name)) 189 Eventually(session).Should(Say("%s\\s+%s\\s+fake service\\s+%s", getServiceName(broker2), getBrokerPlanNames(broker2), broker2.Name)) 190 Eventually(session).Should(Say("TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.")) 191 Eventually(session).Should(Exit(0)) 192 }) 193 194 When("--no-plans is passed", func() { 195 It("displays a table with broker name", func() { 196 session := helpers.CF("marketplace", "--no-plans") 197 Eventually(session).Should(Say("Getting services from marketplace in org %s / space %s as %s\\.\\.\\.", org2, space2, user)) 198 Eventually(session).Should(Say("OK")) 199 Eventually(session).Should(Say("\n\n")) 200 Eventually(session).Should(Say("service\\s+description\\s+broker")) 201 Eventually(session).Should(Say("%s\\s+fake service\\s+%s", getServiceName(broker2), broker2.Name)) 202 Eventually(session).Should(Say("TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.")) 203 Eventually(session).Should(Exit(0)) 204 }) 205 }) 206 }) 207 }) 208 }) 209 }) 210 211 When("the -s flag is passed", func() { 212 When("an api endpoint is not set", func() { 213 BeforeEach(func() { 214 helpers.UnsetAPI() 215 }) 216 217 It("displays an error message that no API endpoint is set", func() { 218 session := helpers.CF("marketplace") 219 Eventually(session).Should(Say("FAILED")) 220 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 221 Eventually(session).Should(Exit(1)) 222 }) 223 }) 224 225 When("the api is set", func() { 226 When("not logged in", func() { 227 BeforeEach(func() { 228 helpers.LogoutCF() 229 }) 230 231 When("the specified service does not exist", func() { 232 It("displays an error that the service doesn't exist", func() { 233 session := helpers.CF("marketplace", "-s", "not-found-service") 234 Eventually(session).Should(Say("Getting service plan information for service not-found-service\\.\\.\\.")) 235 Eventually(session).Should(Say("FAILED")) 236 Eventually(session.Err).Should(Say("Service offering 'not-found-service' not found")) 237 Eventually(session).Should(Exit(1)) 238 }) 239 }) 240 241 When("the specified service exists", func() { 242 var ( 243 broker helpers.ServiceBroker 244 org string 245 space string 246 ) 247 248 BeforeEach(func() { 249 org = helpers.NewOrgName() 250 space = helpers.NewSpaceName() 251 helpers.SetupCF(org, space) 252 helpers.TargetOrgAndSpace(org, space) 253 254 domain := helpers.DefaultSharedDomain() 255 256 broker = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE"), "SERVICE-PLAN") 257 enableServiceAccess(broker) 258 259 helpers.LogoutCF() 260 }) 261 262 AfterEach(func() { 263 helpers.LoginCF() 264 helpers.TargetOrgAndSpace(org, space) 265 broker.Destroy() 266 helpers.QuickDeleteOrg(org) 267 }) 268 269 It("displays extended information about the service", func() { 270 description := "Shared fake Server, 5tb persistent disk, 40 max concurrent connections" 271 session := helpers.CF("marketplace", "-s", getServiceName(broker)) 272 Eventually(session).Should(Say("Getting service plan information for service %s\\.\\.\\.", getServiceName(broker))) 273 Eventually(session).Should(Say("OK")) 274 Eventually(session).Should(Say("\n\n")) 275 Eventually(session).Should(Say("service plan\\s+description\\s+free or paid")) 276 Eventually(session).Should(Say("%s\\s+%s\\s+%s", getPlanName(broker), description, "free")) 277 Eventually(session).Should(Exit(0)) 278 }) 279 }) 280 }) 281 282 When("logged in", func() { 283 var user string 284 285 BeforeEach(func() { 286 helpers.LoginCF() 287 user, _ = helpers.GetCredentials() 288 }) 289 290 When("no space is targeted", func() { 291 BeforeEach(func() { 292 helpers.TargetOrg(ReadOnlyOrg) 293 }) 294 295 It("displays an error that a space must be targeted", func() { 296 session := helpers.CF("marketplace", "-s", "service") 297 Eventually(session).Should(Say("FAILED")) 298 Eventually(session.Err).Should(Say("Cannot list plan information for service without a targeted space")) 299 Eventually(session).Should(Exit(1)) 300 }) 301 }) 302 303 When("a space is targeted", func() { 304 BeforeEach(func() { 305 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 306 }) 307 308 When("the specified service does not exist", func() { 309 It("displays an error that the service doesn't exist", func() { 310 session := helpers.CF("marketplace", "-s", "not-found-service") 311 Eventually(session).Should(Say("Getting service plan information for service not-found-service as %s\\.\\.\\.", user)) 312 Eventually(session).Should(Say("FAILED")) 313 Eventually(session.Err).Should(Say("Service offering 'not-found-service' not found")) 314 Eventually(session).Should(Exit(1)) 315 }) 316 }) 317 318 When("the specified service exists", func() { 319 var ( 320 broker helpers.ServiceBroker 321 org string 322 space string 323 ) 324 325 BeforeEach(func() { 326 org = helpers.NewOrgName() 327 space = helpers.NewSpaceName() 328 helpers.SetupCF(org, space) 329 helpers.TargetOrgAndSpace(org, space) 330 331 domain := helpers.DefaultSharedDomain() 332 333 broker = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE"), "SERVICE-PLAN") 334 enableServiceAccess(broker) 335 }) 336 337 AfterEach(func() { 338 broker.Destroy() 339 helpers.QuickDeleteOrg(org) 340 }) 341 342 It("displays extended information about the service", func() { 343 description := "Shared fake Server, 5tb persistent disk, 40 max concurrent connections" 344 session := helpers.CF("marketplace", "-s", getServiceName(broker)) 345 Eventually(session).Should(Say("Getting service plan information for service %s as %s\\.\\.\\.", getServiceName(broker), user)) 346 Eventually(session).Should(Say("OK")) 347 Eventually(session).Should(Say("\n\n")) 348 Eventually(session).Should(Say("service plan\\s+description\\s+free or paid")) 349 Eventually(session).Should(Say("%s\\s+%s\\s+%s", getPlanName(broker), description, "free")) 350 Eventually(session).Should(Exit(0)) 351 }) 352 }) 353 354 When("the specified service is accessible but not in the targeted space", func() { 355 var ( 356 broker helpers.ServiceBroker 357 org string 358 space string 359 ) 360 361 BeforeEach(func() { 362 org = helpers.NewOrgName() 363 space = helpers.NewSpaceName() 364 helpers.SetupCF(org, space) 365 helpers.TargetOrgAndSpace(org, space) 366 367 domain := helpers.DefaultSharedDomain() 368 369 broker = helpers.CreateBroker(domain, helpers.PrefixedRandomName("SERVICE"), "SERVICE-PLAN") 370 enableServiceAccessForOrg(broker, org) 371 372 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 373 }) 374 375 AfterEach(func() { 376 helpers.TargetOrgAndSpace(org, space) 377 broker.Destroy() 378 helpers.QuickDeleteOrg(org) 379 }) 380 381 It("displays an error that the service doesn't exist", func() { 382 session := helpers.CF("marketplace", "-s", getServiceName(broker)) 383 Eventually(session).Should(Say("Getting service plan information for service %s as %s\\.\\.\\.", getServiceName(broker), user)) 384 Eventually(session).Should(Say("FAILED")) 385 Eventually(session.Err).Should(Say("Service offering '%s' not found", getServiceName(broker))) 386 Eventually(session).Should(Exit(1)) 387 }) 388 }) 389 }) 390 }) 391 }) 392 }) 393 }) 394 }) 395 396 func enableServiceAccess(broker helpers.ServiceBroker) { 397 Eventually(helpers.CF("enable-service-access", getServiceName(broker))).Should(Exit(0)) 398 } 399 400 func enableServiceAccessForOrg(broker helpers.ServiceBroker, orgName string) { 401 Eventually(helpers.CF("enable-service-access", getServiceName(broker), "-o", orgName)).Should(Exit(0)) 402 } 403 404 func getServiceName(broker helpers.ServiceBroker) string { 405 return broker.Service.Name 406 } 407 408 func getPlanName(broker helpers.ServiceBroker) string { 409 return broker.SyncPlans[0].Name 410 } 411 412 func getBrokerPlanNames(broker helpers.ServiceBroker) string { 413 return strings.Join(plansToNames(append(broker.SyncPlans, broker.AsyncPlans...)), ", ") 414 } 415 416 func plansToNames(plans []helpers.Plan) []string { 417 planNames := []string{} 418 for _, plan := range plans { 419 planNames = append(planNames, plan.Name) 420 } 421 return planNames 422 }