github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/marketplace_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/assets/hydrabroker/config" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers/servicebrokerstub" 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 matchMarketplaceHelpMessage := SatisfyAll( 18 Say(`NAME:`), 19 Say(`marketplace - List available offerings in the marketplace`), 20 Say(`USAGE:`), 21 Say(`cf marketplace \[-e SERVICE_OFFERING\] \[-b SERVICE_BROKER\] \[--no-plans\]`), 22 Say(`ALIAS:`), 23 Say(`m`), 24 Say(`OPTIONS:`), 25 Say(`-e\s+Show plan details for a particular service offering`), 26 Say(`--no-plans\s+Hide plan information for service offerings`), 27 Say(`--show-unavailable\s+Show plans that are not available for use`), 28 Say(`create-service, services`), 29 ) 30 31 When("the --help flag is set", func() { 32 It("displays command usage to output", func() { 33 session := helpers.CF("marketplace", "--help") 34 Eventually(session).Should(Exit(0)) 35 Expect(session.Out).To(matchMarketplaceHelpMessage) 36 }) 37 }) 38 39 When("more than required number of args are passed", func() { 40 It("displays an error message with help text and exits 1", func() { 41 session := helpers.CF("marketplace", "lala") 42 Eventually(session).Should(Exit(1)) 43 Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "lala"`)) 44 Expect(session.Out).To(matchMarketplaceHelpMessage) 45 }) 46 }) 47 }) 48 49 When("an API target is not set", func() { 50 BeforeEach(func() { 51 helpers.UnsetAPI() 52 }) 53 54 It("displays an error message that no API endpoint is set", func() { 55 session := helpers.CF("marketplace") 56 Eventually(session).Should(Exit(1)) 57 58 Expect(session.Out).To(Say("FAILED")) 59 Expect(session.Err).To(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`)) 60 }) 61 }) 62 63 When("service offerings are registered", func() { 64 const ( 65 mixedOfferingIndex = iota 66 publicOfferingIndex 67 privateOfferingIndex 68 ) 69 70 const ( 71 privatePlanIndex = iota 72 publicChargedPlanIndex 73 org1PlanIndex 74 org2PlanIndex 75 ) 76 77 var ( 78 session *Session 79 args []string 80 username string 81 org1, org2 string 82 space1, space2 string 83 privatePlanName string 84 publicPlanName string 85 org1PlanName string 86 org2PlanName string 87 mixedOfferingName string 88 publicOfferingName string 89 privateOfferingName string 90 broker *servicebrokerstub.ServiceBrokerStub 91 ) 92 93 deactivateOrg1Plan := func() { 94 helpers.CreateManagedServiceInstance( 95 broker.Services[mixedOfferingIndex].Name, 96 broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].Name, 97 helpers.NewServiceInstanceName(), 98 ) 99 100 broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].Name = helpers.NewServiceOfferingName() 101 broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].ID = helpers.RandomName() 102 103 broker.Configure().Register() 104 } 105 106 JustBeforeEach(func() { 107 session = helpers.CF(append([]string{"marketplace"}, args...)...) 108 Eventually(session).Should(Exit(0)) 109 }) 110 111 BeforeEach(func() { 112 args = nil 113 114 helpers.LoginCF() 115 116 org1 = helpers.NewOrgName() 117 org2 = helpers.NewOrgName() 118 space1 = helpers.NewSpaceName() 119 space2 = helpers.NewSpaceName() 120 121 helpers.CreateOrgAndSpace(org1, space1) 122 helpers.CreateOrgAndSpace(org2, space2) 123 124 username, _ = helpers.GetCredentials() 125 126 broker = servicebrokerstub.New().WithServiceOfferings(3).WithPlans(5) 127 128 mixedOfferingName = helpers.PrefixedRandomName("INTEGRATION-OFFERING-MIXED") 129 broker.Services[mixedOfferingIndex].Name = mixedOfferingName 130 131 privatePlanName = helpers.PrefixedRandomName("INTEGRATION-PLAN-PRIVATE") 132 broker.Services[mixedOfferingIndex].Plans[privatePlanIndex].Name = privatePlanName 133 134 publicPlanName = helpers.PrefixedRandomName("INTEGRATION-PLAN-PUBLIC") 135 broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Name = publicPlanName 136 broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Free = false 137 broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Costs = []config.Cost{ 138 { 139 Amount: map[string]float64{"gbp": 600.00, "usd": 649.00}, 140 Unit: "MONTHLY", 141 }, 142 { 143 Amount: map[string]float64{"usd": 0.999}, 144 Unit: "1GB of messages over 20GB", 145 }, 146 } 147 broker.ServiceAccessConfig = append(broker.ServiceAccessConfig, servicebrokerstub.ServiceAccessConfig{ 148 OfferingName: mixedOfferingName, 149 PlanName: publicPlanName, 150 }) 151 152 org1PlanName = helpers.PrefixedRandomName("INTEGRATION-PLAN-ORG1") 153 broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].Name = org1PlanName 154 broker.ServiceAccessConfig = append(broker.ServiceAccessConfig, servicebrokerstub.ServiceAccessConfig{ 155 OfferingName: mixedOfferingName, 156 PlanName: org1PlanName, 157 OrgName: org1, 158 }) 159 160 org2PlanName = helpers.PrefixedRandomName("INTEGRATION-PLAN-ORG2") 161 broker.Services[mixedOfferingIndex].Plans[org2PlanIndex].Name = org2PlanName 162 broker.ServiceAccessConfig = append(broker.ServiceAccessConfig, servicebrokerstub.ServiceAccessConfig{ 163 OfferingName: mixedOfferingName, 164 PlanName: org2PlanName, 165 OrgName: org2, 166 }) 167 168 publicOfferingName = helpers.PrefixedRandomName("INTEGRATION-OFFERING-PUBLIC") 169 broker.Services[publicOfferingIndex].Name = publicOfferingName 170 broker.ServiceAccessConfig = append(broker.ServiceAccessConfig, servicebrokerstub.ServiceAccessConfig{ 171 OfferingName: publicOfferingName, 172 }) 173 174 privateOfferingName = helpers.PrefixedRandomName("INTEGRATION-OFFERING-PUBLIC") 175 broker.Services[privateOfferingIndex].Name = privateOfferingName 176 177 broker.EnableServiceAccess() 178 179 helpers.TargetOrgAndSpace(org1, space1) 180 }) 181 182 AfterEach(func() { 183 helpers.QuickDeleteOrg(org1) 184 helpers.QuickDeleteOrg(org2) 185 broker.Forget() 186 }) 187 188 Describe("service offerings table", func() { 189 It("shows the available offerings and plans", func() { 190 expectedMixedOfferingPlans := fmt.Sprintf("%s, %s", publicPlanName, org1PlanName) 191 Expect(session.Out).To(SatisfyAll( 192 Say(`Getting all service offerings from marketplace in org %s / space %s as %s\.\.\.\n`, org1, space1, username), 193 Say(`\n`), 194 Say(`offering\s+plans\s+description\s+broker\n`), 195 Say(`%s\s+%s\s+%s\s+%s\n`, mixedOfferingName, expectedMixedOfferingPlans, broker.Services[mixedOfferingIndex].Description, broker.Name), 196 Say(`%s\s+%s\s+%s\s+%s\n`, publicOfferingName, broker.Services[publicOfferingIndex].Plans[0].Name, broker.Services[publicOfferingIndex].Description, broker.Name), 197 Say(`\n`), 198 Say(`TIP: Use 'cf marketplace -e SERVICE_OFFERING' to view descriptions of individual plans of a given service offering\.\n`), 199 )) 200 201 Expect(session.Out).NotTo(SatisfyAny( 202 Say(privateOfferingName), 203 Say(privatePlanName), 204 Say(org2PlanName), 205 )) 206 }) 207 208 When("logged out", func() { 209 BeforeEach(func() { 210 helpers.LogoutCF() 211 }) 212 213 AfterEach(func() { 214 helpers.LoginCF() 215 }) 216 217 It("only shows the public plans", func() { 218 Expect(session.Out).To(SatisfyAll( 219 Say(`Getting all service offerings from marketplace\.\.\.\n`), 220 Say(`\n`), 221 Say(`offering\s+plans\s+description\s+broker\n`), 222 Say(`%s\s+%s\s+%s\s+%s\n`, mixedOfferingName, publicPlanName, broker.Services[mixedOfferingIndex].Description, broker.Name), 223 Say(`%s\s+%s\s+%s\s+%s\n`, publicOfferingName, broker.Services[publicOfferingIndex].Plans[0].Name, broker.Services[publicOfferingIndex].Description, broker.Name), 224 Say(`\n`), 225 Say(`TIP: Use 'cf marketplace -e SERVICE_OFFERING' to view descriptions of individual plans of a given service offering\.\n`), 226 )) 227 228 Expect(session.Out).NotTo(SatisfyAny( 229 Say(privateOfferingName), 230 Say(privatePlanName), 231 Say(org1PlanName), 232 Say(org2PlanName), 233 )) 234 }) 235 }) 236 237 When("filtering by service broker name", func() { 238 var secondServiceBroker *servicebrokerstub.ServiceBrokerStub 239 240 BeforeEach(func() { 241 secondServiceBroker = servicebrokerstub.New().WithServiceOfferings(1).WithPlans(1).EnableServiceAccess() 242 243 args = append(args, "-b", secondServiceBroker.Name) 244 }) 245 246 AfterEach(func() { 247 secondServiceBroker.Forget() 248 }) 249 250 It("only shows plans for the selected broker", func() { 251 Expect(session.Out).To(SatisfyAll( 252 Say(`Getting all service offerings from marketplace for service broker %s in org %s / space %s as %s\.\.\.\n`, secondServiceBroker.Name, org1, space1, username), 253 Say(`\n`), 254 Say(`offering\s+plans\s+description\s+broker\n`), 255 Say(`%s\s+%s\s+%s\s+%s\n`, secondServiceBroker.FirstServiceOfferingName(), secondServiceBroker.FirstServicePlanName(), secondServiceBroker.FirstServiceOfferingDescription(), secondServiceBroker.Name), 256 Say(`\n`), 257 Say(`TIP: Use 'cf marketplace -e SERVICE_OFFERING' to view descriptions of individual plans of a given service offering\.\n`), 258 )) 259 260 Expect(session.Out).NotTo(Say(broker.Name)) 261 }) 262 }) 263 264 When("a service plan is unavailable", func() { 265 BeforeEach(func() { 266 deactivateOrg1Plan() 267 }) 268 269 It("does not show the unavailable plan", func() { 270 Expect(string(session.Out.Contents())).NotTo(ContainSubstring(org1PlanName)) 271 }) 272 273 When("the --show-unavailable flag is specified", func() { 274 BeforeEach(func() { 275 args = append(args, "--show-unavailable") 276 }) 277 278 It("shows unavailable plans", func() { 279 expectedPlans := fmt.Sprintf("%s, %s", publicPlanName, org1PlanName) 280 Expect(session.Out).To(Say(`%s\s+%s\s+%s\s+%s\n`, mixedOfferingName, expectedPlans, broker.Services[mixedOfferingIndex].Description, broker.Name)) 281 }) 282 }) 283 }) 284 }) 285 286 Describe("service plans table", func() { 287 BeforeEach(func() { 288 args = append(args, "-e", mixedOfferingName) 289 }) 290 291 It("shows the available plans", func() { 292 Expect(session.Out).To(SatisfyAll( 293 Say(`Getting service plan information for service offering %s in org %s / space %s as %s\.\.\.\n`, mixedOfferingName, org1, space1, username), 294 Say(`\n`), 295 Say(`broker: %s\n`, broker.Name), 296 Say(`plan\s+description\s+free or paid\s+costs\n`), 297 Say(`%s\s+%s\s+%s\s+%s\n`, publicPlanName, broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Description, "paid", "GBP 600.00/MONTHLY, USD 649.00/MONTHLY, USD 1.00/1GB of messages over 20GB"), 298 Say(`%s\s+%s\s+%s\s+\n`, org1PlanName, broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].Description, "free"), 299 )) 300 301 Expect(session.Out).NotTo(SatisfyAny( 302 Say(publicOfferingName), 303 Say(privatePlanName), 304 Say(org2PlanName), 305 )) 306 }) 307 308 When("logged out", func() { 309 BeforeEach(func() { 310 helpers.LogoutCF() 311 }) 312 313 AfterEach(func() { 314 helpers.LoginCF() 315 }) 316 317 It("only shows the public plans", func() { 318 Expect(session.Out).To(SatisfyAll( 319 Say(`Getting service plan information for service offering %s\.\.\.\n`, mixedOfferingName), 320 Say(`\n`), 321 Say(`broker: %s\n`, broker.Name), 322 Say(`plan\s+description\s+free or paid\s+costs\n`), 323 Say(`%s\s+%s\s+%s\s+%s\n`, publicPlanName, broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Description, "paid", "GBP 600.00/MONTHLY, USD 649.00/MONTHLY, USD 1.00/1GB of messages over 20GB"), 324 )) 325 326 Expect(session.Out).NotTo(SatisfyAny( 327 Say(publicOfferingName), 328 Say(privatePlanName), 329 Say(org1PlanName), 330 Say(org2PlanName), 331 )) 332 }) 333 }) 334 335 When("filtering by service broker name", func() { 336 var secondServiceBroker *servicebrokerstub.ServiceBrokerStub 337 338 BeforeEach(func() { 339 secondServiceBroker = servicebrokerstub.New().WithServiceOfferings(1).WithPlans(1) 340 secondServiceBroker.Services[0].Name = mixedOfferingName 341 secondServiceBroker.EnableServiceAccess() 342 343 args = append(args, "-b", secondServiceBroker.Name) 344 }) 345 346 AfterEach(func() { 347 secondServiceBroker.Forget() 348 }) 349 350 It("only shows plans for the selected broker", func() { 351 Expect(session.Out).To(SatisfyAll( 352 Say(`Getting service plan information for service offering %s from service broker %s in org %s / space %s as %s\.\.\.\n`, mixedOfferingName, secondServiceBroker.Name, org1, space1, username), 353 Say(`\n`), 354 Say(`broker: %s\n`, secondServiceBroker.Name), 355 Say(`plan\s+description\s+free or paid\s+costs\n`), 356 Say(`%s\s+%s\s+%s\s+\n`, secondServiceBroker.FirstServicePlanName(), secondServiceBroker.FirstServicePlanDescription(), "free"), 357 )) 358 359 Expect(session.Out).NotTo(SatisfyAny( 360 Say(broker.Name), 361 Say(publicPlanName), 362 Say(org1PlanName), 363 )) 364 }) 365 }) 366 367 When("a service plan is unavailable", func() { 368 BeforeEach(func() { 369 deactivateOrg1Plan() 370 }) 371 372 It("does not show the unavailable plan", func() { 373 Expect(string(session.Out.Contents())).NotTo(ContainSubstring(org1PlanName)) 374 }) 375 376 When("the --show-unavailable flag is specified", func() { 377 BeforeEach(func() { 378 args = append(args, "--show-unavailable") 379 }) 380 381 It("shows unavailable plans and the plan availability column", func() { 382 Expect(session.Out).To(SatisfyAll( 383 Say(`Getting service plan information for service offering %s in org %s / space %s as %s\.\.\.\n`, mixedOfferingName, org1, space1, username), 384 Say(`\n`), 385 Say(`broker: %s\n`, broker.Name), 386 Say(`plan\s+description\s+free or paid\s+costs\s+available\n`), 387 Say(`%s\s+%s\s+%s\s+%s\s+%s\n`, publicPlanName, broker.Services[mixedOfferingIndex].Plans[publicChargedPlanIndex].Description, "paid", "GBP 600.00/MONTHLY, USD 649.00/MONTHLY, USD 1.00/1GB of messages over 20GB", "yes"), 388 Say(`%s\s+%s\s+%s\s+%s\n`, org1PlanName, broker.Services[mixedOfferingIndex].Plans[org1PlanIndex].Description, "free", "no"), 389 )) 390 }) 391 }) 392 }) 393 394 // Available 395 396 //When("a plan has cost information", func() { 397 // var brokerWithCosts *servicebrokerstub.ServiceBrokerStub 398 // 399 // BeforeEach(func() { 400 // brokerWithCosts = servicebrokerstub.New().WithServiceOfferings(1).WithPlans(4) 401 // 402 // brokerWithCosts.Services[0].Plans[0].Free = false 403 // brokerWithCosts.Services[0].Plans[0].Costs = []config.Cost{ 404 // { 405 // Amount: map[string]float64{"gbp": 600.00, "usd": 649.00}, 406 // Unit: "MONTHLY", 407 // }, 408 // { 409 // Amount: map[string]float64{"usd": 0.999}, 410 // Unit: "1GB of messages over 20GB", 411 // }, 412 // } 413 // 414 // brokerWithCosts.Services[0].Plans[1].Free = false 415 // brokerWithCosts.Services[0].Plans[1].Costs = []config.Cost{{ 416 // Amount: map[string]float64{"gbp": 600.00}, 417 // Unit: "MONTHLY", 418 // }} 419 // 420 // brokerWithCosts.Services[0].Plans[2].Free = false 421 // 422 // brokerWithCosts.EnableServiceAccess() 423 // }) 424 // 425 // AfterEach(func() { 426 // brokerWithCosts.Forget() 427 // }) 428 // 429 // It("shows the costs", func() { 430 // Expect(session.Out).To(SatisfyAll( 431 // Say(`Getting service plan information for service offering %s in org %s / space %s as %s\.\.\.\n`, mixedOfferingName, org1, space1, username), 432 // Say(`\n`), 433 // Say(`broker: %s\n`, brokerWithCosts.Name), 434 // Say(`plan\s+description\s+free or paid\s+costs\n`), 435 // Say(`%s\s+%s\s+%s\s+%s\n`, brokerWithCosts.Services[0].Plans[0].Name, brokerWithCosts.Services[0].Plans[0].Description, "paid", "GBP 600.00/MONTHLY, USD 649.00/MONTHLY, USD 1.00/1GB of messages over 20GB"), 436 // Say(`%s\s+%s\s+%s\s+%s\n`, brokerWithCosts.Services[0].Plans[1].Name, brokerWithCosts.Services[0].Plans[1].Description, "paid", "GBP 600.00/MONTHLY"), 437 // Say(`%s\s+%s\s+%s\s+\n`, brokerWithCosts.Services[0].Plans[2].Name, brokerWithCosts.Services[0].Plans[2].Description, "paid"), 438 // Say(`%s\s+%s\s+%s\s+\n`, brokerWithCosts.Services[0].Plans[3].Name, brokerWithCosts.Services[0].Plans[3].Description, "free"), 439 // )) 440 // }) 441 //}) 442 }) 443 444 }) 445 })