github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/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/assets/hydrabroker/config" 6 "code.cloudfoundry.org/cli/integration/helpers" 7 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("services command", func() { 15 var ( 16 userName string 17 ) 18 19 BeforeEach(func() { 20 userName, _ = helpers.GetCredentials() 21 }) 22 23 Describe("help", func() { 24 When("--help flag is set", func() { 25 It("Displays command usage to output", func() { 26 session := helpers.CF("services", "--help") 27 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("services - List all service instances in the target space")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf services")) 32 Eventually(session).Should(Say("ALIAS:")) 33 Eventually(session).Should(Say("s")) 34 Eventually(session).Should(Say("SEE ALSO:")) 35 Eventually(session).Should(Say("create-service, marketplace")) 36 37 Eventually(session).Should(Exit(0)) 38 }) 39 }) 40 }) 41 42 Context("has no services", func() { 43 BeforeEach(func() { 44 helpers.LoginCF() 45 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 46 }) 47 48 It("tells the user 'no services found'", func() { 49 session := helpers.CF("services") 50 51 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", ReadOnlyOrg, ReadOnlySpace, userName)) 52 Eventually(session).Should(Say("No services found")) 53 Eventually(session).Should(Exit(0)) 54 }) 55 }) 56 57 Context("has services and applications", func() { 58 var ( 59 orgName string 60 spaceName string 61 62 broker *servicebrokerstub.ServiceBrokerStub 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 broker = servicebrokerstub.EnableServiceAccess() 84 85 managedService1 = helpers.PrefixedRandomName("MANAGED1") 86 managedService2 = helpers.PrefixedRandomName("MANAGED2") 87 Eventually(helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService1)).Should(Exit(0)) 88 Eventually(helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), 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.Forget() 114 helpers.QuickDeleteOrg(orgName) 115 }) 116 117 When("CAPI version is < 2.125.0", func() { 118 It("displays all service information", func() { 119 session := helpers.CF("services") 120 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 121 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) 122 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, "create succeeded")) 123 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, appName2, "create succeeded")) 124 Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) 125 Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) 126 Eventually(session).Should(Exit(0)) 127 }) 128 }) 129 130 When("CAPI version is >= 2.125.0 (broker name is available in summary endpoint)", func() { 131 It("displays all service information", func() { 132 session := helpers.CF("services") 133 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 134 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) 135 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, "create succeeded", broker.Name)) 136 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s+%s`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, appName2, "create succeeded", broker.Name)) 137 Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) 138 Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) 139 Eventually(session).Should(Exit(0)) 140 }) 141 }) 142 }) 143 144 Context("has only services", func() { 145 const ( 146 serviceInstanceWithNoMaintenanceInfo = "s3" 147 serviceInstanceWithOldMaintenanceInfo = "s2" 148 serviceInstanceWithNewMaintenanceInfo = "s1" 149 ) 150 151 var ( 152 broker *servicebrokerstub.ServiceBrokerStub 153 orgName string 154 spaceName string 155 service string 156 planWithNoMaintenanceInfo string 157 planWithMaintenanceInfo string 158 userProvidedService string 159 ) 160 161 BeforeEach(func() { 162 orgName = helpers.NewOrgName() 163 spaceName = helpers.NewSpaceName() 164 helpers.SetupCF(orgName, spaceName) 165 166 broker = servicebrokerstub.New().WithPlans(2) 167 168 service = broker.FirstServiceOfferingName() 169 planWithMaintenanceInfo = broker.Services[0].Plans[0].Name 170 broker.Services[0].Plans[0].MaintenanceInfo = &config.MaintenanceInfo{Version: "1.2.3"} 171 planWithNoMaintenanceInfo = broker.Services[0].Plans[1].Name 172 broker.Services[0].Plans[1].MaintenanceInfo = nil 173 174 broker.EnableServiceAccess() 175 176 Eventually(helpers.CF("create-service", service, planWithNoMaintenanceInfo, serviceInstanceWithNoMaintenanceInfo)).Should(Exit(0)) 177 Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithOldMaintenanceInfo)).Should(Exit(0)) 178 179 broker.Services[0].Plans[0].MaintenanceInfo = &config.MaintenanceInfo{Version: "2.0.0"} 180 181 broker.Configure().Register() 182 Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithNewMaintenanceInfo)).Should(Exit(0)) 183 184 userProvidedService = helpers.PrefixedRandomName("UPS1") 185 Eventually(helpers.CF("cups", userProvidedService, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0)) 186 }) 187 188 AfterEach(func() { 189 Eventually(helpers.CF("delete-service", serviceInstanceWithNoMaintenanceInfo, "-f")).Should(Exit(0)) 190 Eventually(helpers.CF("delete-service", serviceInstanceWithOldMaintenanceInfo, "-f")).Should(Exit(0)) 191 Eventually(helpers.CF("delete-service", serviceInstanceWithNewMaintenanceInfo, "-f")).Should(Exit(0)) 192 193 broker.Forget() 194 helpers.QuickDeleteOrg(orgName) 195 }) 196 197 When("CAPI version supports maintenance_info in summary endpoint", func() { 198 BeforeEach(func() { 199 helpers.SkipIfVersionLessThan(ccversion.MinVersionMaintenanceInfoInSummaryV2) 200 }) 201 202 It("displays all service information", func() { 203 session := helpers.CF("services") 204 Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) 205 Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker\s+upgrade available`)) 206 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")) 207 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")) 208 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithNoMaintenanceInfo, service, planWithNoMaintenanceInfo, "", "create succeeded", broker.Name, "")) 209 Eventually(session).Should(Say(`%s\s+%s\s+`, userProvidedService, "user-provided")) 210 Eventually(session).Should(Exit(0)) 211 }) 212 }) 213 }) 214 })