github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/shared/isolated/services_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 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 var ( 15 userName string 16 ) 17 18 BeforeEach(func() { 19 userName, _ = helpers.GetCredentials() 20 }) 21 22 Describe("help", func() { 23 When("--help flag is set", func() { 24 It("Displays command usage to output", func() { 25 session := helpers.CF("services", "--help") 26 27 Eventually(session).Should(Say("NAME:")) 28 Eventually(session).Should(Say("services - List all service instances in the target space")) 29 Eventually(session).Should(Say("USAGE:")) 30 Eventually(session).Should(Say("cf services")) 31 Eventually(session).Should(Say("ALIAS:")) 32 Eventually(session).Should(Say("s")) 33 Eventually(session).Should(Say("SEE ALSO:")) 34 Eventually(session).Should(Say("create-service, marketplace")) 35 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 }) 40 41 Context("has no services", func() { 42 BeforeEach(func() { 43 helpers.LoginCF() 44 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 45 }) 46 47 It("tells the user 'no services found'", func() { 48 session := helpers.CF("services") 49 50 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", ReadOnlyOrg, ReadOnlySpace, userName)) 51 Eventually(session).Should(Say("No services found")) 52 Eventually(session).Should(Exit(0)) 53 }) 54 }) 55 56 Context("has services and applications", func() { 57 var ( 58 orgName string 59 spaceName string 60 61 broker *fakeservicebroker.FakeServiceBroker 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 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 83 Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0)) 84 85 managedService1 = helpers.PrefixedRandomName("MANAGED1") 86 managedService2 = helpers.PrefixedRandomName("MANAGED2") 87 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), managedService1)).Should(Exit(0)) 88 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), managedService2)).Should(Exit(0)) 89 90 appName1 = helpers.PrefixedRandomName("APP1") 91 appName2 = helpers.PrefixedRandomName("APP2") 92 helpers.WithHelloWorldApp(func(appDir string) { 93 Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 94 Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 95 }) 96 Eventually(helpers.CF("bind-service", appName1, managedService1)).Should(Exit(0)) 97 Eventually(helpers.CF("bind-service", appName1, managedService2)).Should(Exit(0)) 98 Eventually(helpers.CF("bind-service", appName1, userProvidedService1)).Should(Exit(0)) 99 Eventually(helpers.CF("bind-service", appName1, userProvidedService2)).Should(Exit(0)) 100 Eventually(helpers.CF("bind-service", appName2, managedService2)).Should(Exit(0)) 101 Eventually(helpers.CF("bind-service", appName2, userProvidedService2)).Should(Exit(0)) 102 }) 103 104 AfterEach(func() { 105 Eventually(helpers.CF("unbind-service", appName1, managedService1)).Should(Exit(0)) 106 Eventually(helpers.CF("unbind-service", appName1, managedService2)).Should(Exit(0)) 107 Eventually(helpers.CF("unbind-service", appName1, userProvidedService1)).Should(Exit(0)) 108 Eventually(helpers.CF("unbind-service", appName1, userProvidedService2)).Should(Exit(0)) 109 Eventually(helpers.CF("unbind-service", appName2, managedService2)).Should(Exit(0)) 110 Eventually(helpers.CF("unbind-service", appName2, userProvidedService2)).Should(Exit(0)) 111 Eventually(helpers.CF("delete-service", managedService1, "-f")).Should(Exit(0)) 112 Eventually(helpers.CF("delete-service", managedService2, "-f")).Should(Exit(0)) 113 broker.Destroy() 114 helpers.QuickDeleteOrg(orgName) 115 }) 116 117 When("CAPI version is < 2.125.0", func() { 118 BeforeEach(func() { 119 helpers.SkipIfVersionAtLeast(ccversion.MinVersionMultiServiceRegistrationV2) 120 }) 121 122 It("displays all service information", func() { 123 session := helpers.CF("services") 124 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 125 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) 126 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s`, managedService1, broker.ServiceName(), broker.ServicePlanName(), appName1, "create succeeded")) 127 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s`, managedService2, broker.ServiceName(), broker.ServicePlanName(), appName1, appName2, "create succeeded")) 128 Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) 129 Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) 130 Eventually(session).Should(Exit(0)) 131 }) 132 }) 133 134 When("CAPI version is >= 2.125.0 (broker name is available in summary endpoint)", func() { 135 BeforeEach(func() { 136 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 137 }) 138 139 It("displays all service information", func() { 140 session := helpers.CF("services") 141 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 142 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) 143 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, managedService1, broker.ServiceName(), broker.ServicePlanName(), appName1, "create succeeded", broker.Name())) 144 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s+%s`, managedService2, broker.ServiceName(), broker.ServicePlanName(), appName1, appName2, "create succeeded", broker.Name())) 145 Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) 146 Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) 147 Eventually(session).Should(Exit(0)) 148 }) 149 }) 150 }) 151 152 Context("has only services", func() { 153 const ( 154 serviceInstanceWithNoMaintenanceInfo = "s3" 155 serviceInstanceWithOldMaintenanceInfo = "s2" 156 serviceInstanceWithNewMaintenanceInfo = "s1" 157 ) 158 159 var ( 160 broker *fakeservicebroker.FakeServiceBroker 161 orgName string 162 spaceName string 163 service string 164 planWithNoMaintenanceInfo string 165 planWithMaintenanceInfo string 166 userProvidedService string 167 ) 168 169 BeforeEach(func() { 170 orgName = helpers.NewOrgName() 171 spaceName = helpers.NewSpaceName() 172 helpers.SetupCF(orgName, spaceName) 173 174 broker = fakeservicebroker.New() 175 176 service = broker.ServiceName() 177 planWithMaintenanceInfo = broker.Services[0].Plans[0].Name 178 broker.Services[0].Plans[0].SetMaintenanceInfo("1.2.3", "") 179 planWithNoMaintenanceInfo = broker.Services[0].Plans[1].Name 180 broker.Services[0].Plans[1].RemoveMaintenanceInfo() 181 182 broker.EnsureBrokerIsAvailable() 183 184 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 185 186 Eventually(helpers.CF("create-service", service, planWithNoMaintenanceInfo, serviceInstanceWithNoMaintenanceInfo)).Should(Exit(0)) 187 Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithOldMaintenanceInfo)).Should(Exit(0)) 188 189 broker.Services[0].Plans[0].SetMaintenanceInfo("2.0.0", "") 190 broker.Update() 191 Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithNewMaintenanceInfo)).Should(Exit(0)) 192 193 userProvidedService = helpers.PrefixedRandomName("UPS1") 194 Eventually(helpers.CF("cups", userProvidedService, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0)) 195 }) 196 197 AfterEach(func() { 198 Eventually(helpers.CF("delete-service", serviceInstanceWithNoMaintenanceInfo, "-f")).Should(Exit(0)) 199 Eventually(helpers.CF("delete-service", serviceInstanceWithOldMaintenanceInfo, "-f")).Should(Exit(0)) 200 Eventually(helpers.CF("delete-service", serviceInstanceWithNewMaintenanceInfo, "-f")).Should(Exit(0)) 201 202 broker.Destroy() 203 helpers.QuickDeleteOrg(orgName) 204 }) 205 206 When("CAPI version supports maintenance_info in summary endpoint", func() { 207 BeforeEach(func() { 208 helpers.SkipIfVersionLessThan(ccversion.MinVersionMaintenanceInfoInSummaryV2) 209 }) 210 211 It("displays all service information", func() { 212 session := helpers.CF("services") 213 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 214 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker\s+upgrade available`)) 215 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithNewMaintenanceInfo, service, planWithMaintenanceInfo, "", "create succeeded", broker.Name(), "no")) 216 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithOldMaintenanceInfo, service, planWithMaintenanceInfo, "", "create succeeded", broker.Name(), "yes")) 217 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithNoMaintenanceInfo, service, planWithNoMaintenanceInfo, "", "create succeeded", broker.Name(), "")) 218 Eventually(session).Should(Say(`%s\s+%s\s+`, userProvidedService, "user-provided")) 219 Eventually(session).Should(Exit(0)) 220 }) 221 }) 222 }) 223 })