github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/unbind_service_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("unbind-service command", func() { 12 var ( 13 serviceInstance string 14 appName string 15 ) 16 17 BeforeEach(func() { 18 serviceInstance = helpers.PrefixedRandomName("si") 19 appName = helpers.PrefixedRandomName("app") 20 }) 21 22 Context("when the environment is not setup correctly", func() { 23 Context("when no API endpoint is set", func() { 24 BeforeEach(func() { 25 helpers.UnsetAPI() 26 }) 27 28 It("fails with no API endpoint set message", func() { 29 session := helpers.CF("unbind-service", appName, serviceInstance) 30 Eventually(session.Out).Should(Say("FAILED")) 31 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 32 Eventually(session).Should(Exit(1)) 33 }) 34 }) 35 36 Context("when not logged in", func() { 37 BeforeEach(func() { 38 helpers.LogoutCF() 39 }) 40 41 It("fails with not logged in message", func() { 42 session := helpers.CF("unbind-service", appName, serviceInstance) 43 Eventually(session.Out).Should(Say("FAILED")) 44 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 45 Eventually(session).Should(Exit(1)) 46 }) 47 }) 48 49 Context("when there no org set", func() { 50 BeforeEach(func() { 51 helpers.LogoutCF() 52 helpers.LoginCF() 53 }) 54 55 It("fails with no targeted org error message", func() { 56 session := helpers.CF("unbind-service", appName, serviceInstance) 57 Eventually(session.Out).Should(Say("FAILED")) 58 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 Context("when there no space set", func() { 64 BeforeEach(func() { 65 helpers.LogoutCF() 66 helpers.LoginCF() 67 helpers.TargetOrg(ReadOnlyOrg) 68 }) 69 70 It("fails with no targeted space error message", func() { 71 session := helpers.CF("unbind-service", appName, serviceInstance) 72 Eventually(session.Out).Should(Say("FAILED")) 73 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 74 Eventually(session).Should(Exit(1)) 75 }) 76 }) 77 }) 78 79 Context("when the environment is setup correctly", func() { 80 var ( 81 org string 82 space string 83 service string 84 servicePlan string 85 broker helpers.ServiceBroker 86 domain string 87 ) 88 89 BeforeEach(func() { 90 org = helpers.NewOrgName() 91 space = helpers.NewSpaceName() 92 service = helpers.PrefixedRandomName("SERVICE") 93 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 94 95 setupCF(org, space) 96 domain = defaultSharedDomain() 97 }) 98 99 AfterEach(func() { 100 helpers.QuickDeleteOrg(org) 101 }) 102 103 Context("when the service is provided by a user", func() { 104 BeforeEach(func() { 105 Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0)) 106 }) 107 108 AfterEach(func() { 109 Eventually(helpers.CF("delete-service", serviceInstance, "-f")).Should(Exit(0)) 110 }) 111 112 Context("when the service is bound to an app", func() { 113 BeforeEach(func() { 114 helpers.WithHelloWorldApp(func(appDir string) { 115 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 116 }) 117 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 118 }) 119 120 It("unbinds the service", func() { 121 Eventually(helpers.CF("services")).Should(SatisfyAll( 122 Exit(0), 123 Say("%s.*%s", serviceInstance, appName)), 124 ) 125 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 126 Eventually(helpers.CF("services")).Should(SatisfyAll( 127 Exit(0), 128 Not(Say("%s.*%s", serviceInstance, appName)), 129 )) 130 }) 131 }) 132 133 Context("when the service is not bound to an app", func() { 134 BeforeEach(func() { 135 helpers.WithHelloWorldApp(func(appDir string) { 136 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 137 }) 138 }) 139 140 It("returns a warning and continues", func() { 141 session := helpers.CF("unbind-service", appName, serviceInstance) 142 Eventually(session.Out).Should(Say("OK")) 143 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 144 Eventually(session).Should(Exit(0)) 145 }) 146 }) 147 148 Context("when the service does not exist", func() { 149 BeforeEach(func() { 150 helpers.WithHelloWorldApp(func(appDir string) { 151 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 152 }) 153 }) 154 155 It("fails to unbind the service", func() { 156 session := helpers.CF("unbind-service", appName, "does-not-exist") 157 Eventually(session.Out).Should(Say("FAILED")) 158 Eventually(session.Err).Should(Say("Service instance %s not found", "does-not-exist")) 159 Eventually(session).Should(Exit(1)) 160 }) 161 }) 162 163 Context("when the app does not exist", func() { 164 It("fails to unbind the service", func() { 165 session := helpers.CF("unbind-service", "does-not-exist", serviceInstance) 166 Eventually(session.Out).Should(Say("FAILED")) 167 Eventually(session.Err).Should(Say("App %s not found", "does-not-exist")) 168 Eventually(session).Should(Exit(1)) 169 }) 170 }) 171 }) 172 173 Context("when the service is provided by a broker", func() { 174 BeforeEach(func() { 175 broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 176 broker.Push() 177 broker.Configure() 178 broker.Create() 179 180 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 181 }) 182 183 AfterEach(func() { 184 broker.Destroy() 185 }) 186 187 Context("when the service is bound to an app", func() { 188 BeforeEach(func() { 189 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 190 helpers.WithHelloWorldApp(func(appDir string) { 191 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 192 }) 193 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 194 }) 195 196 It("unbinds the service", func() { 197 Eventually(helpers.CF("services")).Should(SatisfyAll( 198 Exit(0), 199 Say("%s.*%s", serviceInstance, appName)), 200 ) 201 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 202 Eventually(helpers.CF("services")).Should(SatisfyAll( 203 Exit(0), 204 Not(Say("%s.*%s", serviceInstance, appName)), 205 )) 206 }) 207 }) 208 209 Context("when the service is not bound to an app", func() { 210 BeforeEach(func() { 211 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 212 helpers.WithHelloWorldApp(func(appDir string) { 213 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 214 }) 215 }) 216 217 It("returns a warning and continues", func() { 218 session := helpers.CF("unbind-service", appName, serviceInstance) 219 Eventually(session.Out).Should(Say("OK")) 220 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 221 Eventually(session).Should(Exit(0)) 222 }) 223 }) 224 225 Context("when the service does not exist", func() { 226 BeforeEach(func() { 227 helpers.WithHelloWorldApp(func(appDir string) { 228 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 229 }) 230 }) 231 232 It("fails to unbind the service", func() { 233 session := helpers.CF("unbind-service", appName, serviceInstance) 234 Eventually(session.Out).Should(Say("FAILED")) 235 Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstance)) 236 Eventually(session).Should(Exit(1)) 237 }) 238 }) 239 240 Context("when the app does not exist", func() { 241 BeforeEach(func() { 242 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 243 }) 244 245 It("fails to unbind the service", func() { 246 session := helpers.CF("unbind-service", appName, serviceInstance) 247 Eventually(session.Out).Should(Say("FAILED")) 248 Eventually(session.Err).Should(Say("App %s not found", appName)) 249 Eventually(session).Should(Exit(1)) 250 }) 251 }) 252 }) 253 }) 254 })