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