github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/services_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("services command", func() {
    12  	var (
    13  		userName string
    14  	)
    15  
    16  	BeforeEach(func() {
    17  		userName, _ = helpers.GetCredentials()
    18  	})
    19  
    20  	Describe("help", func() {
    21  		Context("when --help flag is set", func() {
    22  			It("Displays command usage to output", func() {
    23  				session := helpers.CF("services", "--help")
    24  
    25  				Eventually(session).Should(Say("NAME:"))
    26  				Eventually(session).Should(Say("services - List all service instances in the target space"))
    27  				Eventually(session).Should(Say("USAGE:"))
    28  				Eventually(session).Should(Say("cf services"))
    29  				Eventually(session).Should(Say("ALIAS:"))
    30  				Eventually(session).Should(Say("s"))
    31  				Eventually(session).Should(Say("SEE ALSO:"))
    32  				Eventually(session).Should(Say("create-service, marketplace"))
    33  
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	Context("has no services", func() {
    40  		BeforeEach(func() {
    41  			helpers.LoginCF()
    42  			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
    43  		})
    44  
    45  		It("tells the user 'no services found'", func() {
    46  			session := helpers.CF("services")
    47  
    48  			Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", ReadOnlyOrg, ReadOnlySpace, userName))
    49  			Eventually(session).Should(Say("No services found"))
    50  			Eventually(session).Should(Exit(0))
    51  		})
    52  	})
    53  
    54  	Context("has services", func() {
    55  		var (
    56  			orgName   string
    57  			spaceName string
    58  
    59  			service     string
    60  			servicePlan string
    61  			broker      helpers.ServiceBroker
    62  
    63  			managedService1      string
    64  			managedService2      string
    65  			userProvidedService1 string
    66  			userProvidedService2 string
    67  			appName1             string
    68  			appName2             string
    69  		)
    70  
    71  		BeforeEach(func() {
    72  			orgName = helpers.NewOrgName()
    73  			spaceName = helpers.NewSpaceName()
    74  			helpers.SetupCF(orgName, spaceName)
    75  
    76  			userProvidedService1 = helpers.PrefixedRandomName("UPS1")
    77  			userProvidedService2 = helpers.PrefixedRandomName("UPS2")
    78  
    79  			Eventually(helpers.CF("cups", userProvidedService1, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0))
    80  			Eventually(helpers.CF("cups", userProvidedService2, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0))
    81  
    82  			domain := helpers.DefaultSharedDomain()
    83  			service = helpers.PrefixedRandomName("SERVICE")
    84  			servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
    85  			broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan)
    86  			broker.Push()
    87  			broker.Configure(true)
    88  			broker.Create()
    89  			Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
    90  
    91  			managedService1 = helpers.PrefixedRandomName("MANAGED1")
    92  			managedService2 = helpers.PrefixedRandomName("MANAGED2")
    93  			Eventually(helpers.CF("create-service", service, servicePlan, managedService1)).Should(Exit(0))
    94  			Eventually(helpers.CF("create-service", service, servicePlan, managedService2)).Should(Exit(0))
    95  
    96  			appName1 = helpers.PrefixedRandomName("APP1")
    97  			appName2 = helpers.PrefixedRandomName("APP2")
    98  			helpers.WithHelloWorldApp(func(appDir string) {
    99  				Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   100  				Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   101  			})
   102  			Eventually(helpers.CF("bind-service", appName1, managedService1)).Should(Exit(0))
   103  			Eventually(helpers.CF("bind-service", appName1, managedService2)).Should(Exit(0))
   104  			Eventually(helpers.CF("bind-service", appName1, userProvidedService1)).Should(Exit(0))
   105  			Eventually(helpers.CF("bind-service", appName1, userProvidedService2)).Should(Exit(0))
   106  			Eventually(helpers.CF("bind-service", appName2, managedService2)).Should(Exit(0))
   107  			Eventually(helpers.CF("bind-service", appName2, userProvidedService2)).Should(Exit(0))
   108  		})
   109  
   110  		AfterEach(func() {
   111  			Eventually(helpers.CF("unbind-service", appName1, managedService1)).Should(Exit(0))
   112  			Eventually(helpers.CF("unbind-service", appName1, managedService2)).Should(Exit(0))
   113  			Eventually(helpers.CF("unbind-service", appName1, userProvidedService1)).Should(Exit(0))
   114  			Eventually(helpers.CF("unbind-service", appName1, userProvidedService2)).Should(Exit(0))
   115  			Eventually(helpers.CF("unbind-service", appName2, managedService2)).Should(Exit(0))
   116  			Eventually(helpers.CF("unbind-service", appName2, userProvidedService2)).Should(Exit(0))
   117  			Eventually(helpers.CF("delete-service", managedService1, "-f")).Should(Exit(0))
   118  			Eventually(helpers.CF("delete-service", managedService2, "-f")).Should(Exit(0))
   119  			broker.Destroy()
   120  			helpers.QuickDeleteOrg(orgName)
   121  		})
   122  
   123  		It("displays all service information", func() {
   124  			session := helpers.CF("services")
   125  			Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName))
   126  			Eventually(session).Should(Say("name\\s+service\\s+plan\\s+bound apps\\s+last operation"))
   127  			Eventually(session).Should(Say("%s\\s+%s\\s+%s\\s+%s\\s+%s", managedService1, service, servicePlan, appName1, "create succeeded"))
   128  			Eventually(session).Should(Say("%s\\s+%s\\s+%s\\s+%s, %s\\s+%s", managedService2, service, servicePlan, appName1, appName2, "create succeeded"))
   129  			Eventually(session).Should(Say("%s\\s+%s\\s+%s", userProvidedService1, "user-provided", appName1))
   130  			Eventually(session).Should(Say("%s\\s+%s\\s+%s, %s", userProvidedService2, "user-provided", appName1, appName2))
   131  			Eventually(session).Should(Exit(0))
   132  		})
   133  	})
   134  })