github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+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).Should(Exit(1)) 31 Expect(session.Out).To(Say("FAILED")) 32 Expect(session.Err).To(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 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).Should(Exit(1)) 44 Expect(session.Out).To(Say("FAILED")) 45 Expect(session.Err).To(Say("Not logged in. Use 'cf login' to log in.")) 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).Should(Exit(1)) 58 Expect(session.Out).To(Say("FAILED")) 59 Expect(session.Err).To(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 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).Should(Exit(1)) 73 Expect(session.Out).To(Say("FAILED")) 74 Expect(session.Err).To(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 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.PrefixedRandomName("SPACE") 92 service = helpers.PrefixedRandomName("SERVICE") 93 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 94 95 setupCF(org, space) 96 domain = defaultSharedDomain() 97 }) 98 99 Context("when the service is provided by a user", func() { 100 BeforeEach(func() { 101 Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0)) 102 }) 103 104 AfterEach(func() { 105 Eventually(helpers.CF("delete-service", serviceInstance, "-f")).Should(Exit(0)) 106 }) 107 108 Context("when the service is bound to an app", func() { 109 BeforeEach(func() { 110 helpers.WithHelloWorldApp(func(appDir string) { 111 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 112 }) 113 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 114 }) 115 116 It("unbinds the service", func() { 117 Eventually(helpers.CF("services")).Should(SatisfyAll( 118 Exit(0), 119 Say("%s.*%s", serviceInstance, appName)), 120 ) 121 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 122 Eventually(helpers.CF("services")).Should(SatisfyAll( 123 Exit(0), 124 Not(Say("%s.*%s", serviceInstance, appName)), 125 )) 126 }) 127 }) 128 129 Context("when the service is not bound to an app", func() { 130 BeforeEach(func() { 131 helpers.WithHelloWorldApp(func(appDir string) { 132 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 133 }) 134 }) 135 136 It("returns a warning and continues", func() { 137 session := helpers.CF("unbind-service", appName, serviceInstance) 138 Eventually(session).Should(Exit(0)) 139 Expect(session.Out).To(Say("OK")) 140 Expect(session.Err).To(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 141 }) 142 }) 143 144 Context("when the service does not exist", func() { 145 BeforeEach(func() { 146 helpers.WithHelloWorldApp(func(appDir string) { 147 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 148 }) 149 }) 150 151 It("fails to unbind the service", func() { 152 session := helpers.CF("unbind-service", appName, "does-not-exist") 153 Eventually(session).Should(Exit(1)) 154 Expect(session.Out).To(Say("FAILED")) 155 Expect(session.Err).To(Say("Service instance %s not found", "does-not-exist")) 156 }) 157 }) 158 159 Context("when the app does not exist", func() { 160 It("fails to unbind the service", func() { 161 session := helpers.CF("unbind-service", "does-not-exist", serviceInstance) 162 Eventually(session).Should(Exit(1)) 163 Expect(session.Out).To(Say("FAILED")) 164 Expect(session.Err).To(Say("App %s not found", "does-not-exist")) 165 }) 166 }) 167 }) 168 169 Context("when the service is provided by a broker", func() { 170 BeforeEach(func() { 171 broker = helpers.NewServiceBroker(helpers.PrefixedRandomName("SERVICE-BROKER"), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 172 broker.Push() 173 broker.Configure() 174 broker.Create() 175 176 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 177 }) 178 179 AfterEach(func() { 180 broker.Destroy() 181 }) 182 183 Context("when the service is bound to an app", func() { 184 BeforeEach(func() { 185 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 186 helpers.WithHelloWorldApp(func(appDir string) { 187 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 188 }) 189 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 190 }) 191 192 It("unbinds the service", func() { 193 Eventually(helpers.CF("services")).Should(SatisfyAll( 194 Exit(0), 195 Say("%s.*%s", serviceInstance, appName)), 196 ) 197 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 198 Eventually(helpers.CF("services")).Should(SatisfyAll( 199 Exit(0), 200 Not(Say("%s.*%s", serviceInstance, appName)), 201 )) 202 }) 203 }) 204 205 Context("when the service is not bound to an app", func() { 206 BeforeEach(func() { 207 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 208 helpers.WithHelloWorldApp(func(appDir string) { 209 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 210 }) 211 }) 212 213 It("returns a warning and continues", func() { 214 session := helpers.CF("unbind-service", appName, serviceInstance) 215 Eventually(session).Should(Exit(0)) 216 Expect(session.Out).To(Say("OK")) 217 Expect(session.Err).To(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 218 }) 219 }) 220 221 Context("when the service does not exist", func() { 222 BeforeEach(func() { 223 helpers.WithHelloWorldApp(func(appDir string) { 224 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 225 }) 226 }) 227 228 It("fails to unbind the service", func() { 229 session := helpers.CF("unbind-service", appName, serviceInstance) 230 Eventually(session).Should(Exit(1)) 231 Expect(session.Out).To(Say("FAILED")) 232 Expect(session.Err).To(Say("Service instance %s not found", serviceInstance)) 233 }) 234 }) 235 236 Context("when the app does not exist", func() { 237 BeforeEach(func() { 238 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 239 }) 240 241 It("fails to unbind the service", func() { 242 session := helpers.CF("unbind-service", appName, serviceInstance) 243 Eventually(session).Should(Exit(1)) 244 Expect(session.Out).To(Say("FAILED")) 245 Expect(session.Err).To(Say("App %s not found", appName)) 246 }) 247 }) 248 }) 249 }) 250 })