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