github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/services_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/assets/hydrabroker/config"
     5  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers"
     6  	"github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers/servicebrokerstub"
     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("services command", func() {
    14  	const command = "services"
    15  
    16  	var userName string
    17  
    18  	BeforeEach(func() {
    19  		userName, _ = helpers.GetCredentials()
    20  	})
    21  
    22  	Describe("help", func() {
    23  		matchHelpMessage := SatisfyAll(
    24  			Say(`NAME:\n`),
    25  			Say(`services - List all service instances in the target space\n`),
    26  			Say(`USAGE:\n`),
    27  			Say(`cf services\n`),
    28  			Say(`ALIAS:\n`),
    29  			Say(`s\n`),
    30  			Say(`OPTIONS:\n`),
    31  			Say(`--no-apps\s+Do not retrieve bound apps information\.\n`),
    32  			Say(`SEE ALSO:\n`),
    33  			Say(`create-service, marketplace\n`),
    34  		)
    35  
    36  		When("--help flag is set", func() {
    37  			It("displays command usage", func() {
    38  				session := helpers.CF(command, "--help")
    39  				Eventually(session).Should(Exit(0))
    40  				Expect(session).To(matchHelpMessage)
    41  			})
    42  		})
    43  
    44  		When("an argument is passed", func() {
    45  			It("displays an error message with help text and exits 1", func() {
    46  				session := helpers.CF(command, "lala")
    47  				Eventually(session).Should(Exit(1))
    48  				Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "lala"`))
    49  				Expect(session.Out).To(matchHelpMessage)
    50  			})
    51  		})
    52  
    53  		When("an unknown flag is passed", func() {
    54  			It("displays an error message with help text and exits 1", func() {
    55  				session := helpers.CF(command, "-m")
    56  				Eventually(session).Should(Exit(1))
    57  				Expect(session.Err).To(Say("Incorrect Usage: unknown flag `m'"))
    58  				Expect(session.Out).To(matchHelpMessage)
    59  			})
    60  		})
    61  	})
    62  
    63  	Context("has no services", func() {
    64  		BeforeEach(func() {
    65  			helpers.LoginCF()
    66  			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
    67  		})
    68  
    69  		It("tells the user 'no services found'", func() {
    70  			session := helpers.CF(command)
    71  			Eventually(session).Should(Exit(0))
    72  
    73  			Expect(session).To(SatisfyAll(
    74  				Say(`Getting service instances in org %s / space %s as %s...\n`, ReadOnlyOrg, ReadOnlySpace, userName),
    75  				Say(`No service instances found\.\n`),
    76  			))
    77  		})
    78  	})
    79  
    80  	Context("has services and applications", func() {
    81  		var (
    82  			orgName   string
    83  			spaceName string
    84  
    85  			broker *servicebrokerstub.ServiceBrokerStub
    86  
    87  			managedService1      string
    88  			managedService2      string
    89  			userProvidedService1 string
    90  			userProvidedService2 string
    91  			appName1             string
    92  			appName2             string
    93  		)
    94  
    95  		BeforeEach(func() {
    96  			orgName = helpers.NewOrgName()
    97  			spaceName = helpers.NewSpaceName()
    98  			helpers.SetupCF(orgName, spaceName)
    99  
   100  			userProvidedService1 = helpers.PrefixedRandomName("UPS1")
   101  			userProvidedService2 = helpers.PrefixedRandomName("UPS2")
   102  			Eventually(helpers.CF("cups", userProvidedService1, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0))
   103  			Eventually(helpers.CF("cups", userProvidedService2, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0))
   104  
   105  			broker = servicebrokerstub.New().WithPlans(2).EnableServiceAccess()
   106  			managedService1 = helpers.PrefixedRandomName("MANAGED1")
   107  			managedService2 = helpers.PrefixedRandomName("MANAGED2")
   108  			helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService1)
   109  
   110  			broker.Services[0].Plans[0].MaintenanceInfo = &config.MaintenanceInfo{Version: "2.0.0"}
   111  			broker.Configure().Register()
   112  			helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService2)
   113  
   114  			appName1 = helpers.PrefixedRandomName("APP1")
   115  			appName2 = helpers.PrefixedRandomName("APP2")
   116  			helpers.WithHelloWorldApp(func(appDir string) {
   117  				Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   118  				Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   119  			})
   120  			Eventually(helpers.CF("bind-service", appName1, managedService1)).Should(Exit(0))
   121  			Eventually(helpers.CF("bind-service", appName1, managedService2)).Should(Exit(0))
   122  			Eventually(helpers.CF("bind-service", appName1, userProvidedService1)).Should(Exit(0))
   123  			Eventually(helpers.CF("bind-service", appName1, userProvidedService2)).Should(Exit(0))
   124  			Eventually(helpers.CF("bind-service", appName2, managedService2)).Should(Exit(0))
   125  			Eventually(helpers.CF("bind-service", appName2, userProvidedService2)).Should(Exit(0))
   126  		})
   127  
   128  		AfterEach(func() {
   129  			broker.Forget()
   130  			helpers.QuickDeleteOrg(orgName)
   131  		})
   132  
   133  		It("displays all service information", func() {
   134  			By("including bound apps by default", func() {
   135  				session := helpers.CF(command)
   136  				Eventually(session).Should(Exit(0))
   137  
   138  				Expect(session).To(SatisfyAll(
   139  					Say("Getting service instances in org %s / space %s as %s...", orgName, spaceName, userName),
   140  					Say(`name\s+offering\s+plan\s+bound apps\s+last operation\s+broker\s+upgrade available\n`),
   141  					Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s\n`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, "create succeeded", broker.Name, "yes"),
   142  					Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s+%s\s+%s\n`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, appName2, "create succeeded", broker.Name, "no"),
   143  					Say(`%s\s+%s\s+%s\s+%s\s*\n`, userProvidedService1, "user-provided", appName1, "create succeeded"),
   144  					Say(`%s\s+%s\s+%s, %s\s+%s\s*\n`, userProvidedService2, "user-provided", appName1, appName2, "create succeeded"),
   145  				))
   146  			})
   147  
   148  			By("not showing apps when --no-apps is provided", func() {
   149  				session := helpers.CF(command, "--no-apps")
   150  				Eventually(session).Should(Exit(0))
   151  
   152  				Expect(session).To(SatisfyAll(
   153  					Say("Getting service instances in org %s / space %s as %s...", orgName, spaceName, userName),
   154  					Say(`name\s+offering\s+plan\s+last operation\s+broker\s+upgrade available\n`),
   155  					Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\n`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), "create succeeded", broker.Name, "yes"),
   156  					Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\n`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), "create succeeded", broker.Name, "no"),
   157  					Say(`%s\s+%s\s+%s\s*\n`, userProvidedService1, "user-provided", "create succeeded"),
   158  					Say(`%s\s+%s\s+%s\s*\n`, userProvidedService2, "user-provided", "create succeeded"),
   159  				))
   160  			})
   161  		})
   162  	})
   163  
   164  	Context("has shared service instances", func() {
   165  		var (
   166  			managedService, appNameOnSpaceA, appNameOnSpaceB string
   167  		)
   168  
   169  		BeforeEach(func() {
   170  			orgName := helpers.NewOrgName()
   171  			spaceA := helpers.NewSpaceName()
   172  			spaceB := helpers.NewSpaceName()
   173  			managedService = helpers.PrefixedRandomName("MANAGED1")
   174  			appNameOnSpaceA = helpers.PrefixedRandomName("APP1")
   175  			appNameOnSpaceB = helpers.PrefixedRandomName("APP1")
   176  
   177  			helpers.SetupCF(orgName, spaceA)
   178  			helpers.CreateOrgAndSpace(orgName, spaceB)
   179  			broker := servicebrokerstub.New().WithPlans(2).EnableServiceAccess()
   180  			helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService)
   181  
   182  			helpers.WithHelloWorldApp(func(appDir string) {
   183  				Eventually(helpers.CF("push", appNameOnSpaceA, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   184  			})
   185  			Eventually(helpers.CF("bind-service", appNameOnSpaceA, managedService)).Should(Exit(0))
   186  			Eventually(helpers.CF("share-service", managedService, "-s", spaceB)).Should(Exit(0))
   187  
   188  			helpers.TargetOrgAndSpace(orgName, spaceB)
   189  			helpers.WithHelloWorldApp(func(appDir string) {
   190  				Eventually(helpers.CF("push", appNameOnSpaceB, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   191  			})
   192  			Eventually(helpers.CF("bind-service", appNameOnSpaceB, managedService)).Should(Exit(0))
   193  			helpers.TargetOrgAndSpace(orgName, spaceA)
   194  		})
   195  
   196  		It("should not output bound apps in the shared spaces", func() {
   197  			session := helpers.CF(command)
   198  			Eventually(session).Should(Exit(0))
   199  			Expect(session).To(SatisfyAll(
   200  				Say(managedService),
   201  				Say(appNameOnSpaceA),
   202  				Not(Say(appNameOnSpaceB)),
   203  			))
   204  		})
   205  	})
   206  })