github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/shared/isolated/unbind_service_command_test.go (about) 1 package isolated 2 3 import ( 4 "time" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/integration/helpers" 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("unbind-service command", func() { 15 var ( 16 serviceInstance string 17 appName string 18 ) 19 20 BeforeEach(func() { 21 serviceInstance = helpers.PrefixedRandomName("si") 22 appName = helpers.PrefixedRandomName("app") 23 }) 24 25 When("the environment is not setup correctly", func() { 26 It("fails with the appropriate errors", func() { 27 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "unbind-service", "app-name", "service-name") 28 }) 29 }) 30 31 When("the environment is setup correctly", func() { 32 var ( 33 org string 34 space string 35 service string 36 servicePlan string 37 broker helpers.ServiceBroker 38 domain string 39 ) 40 41 BeforeEach(func() { 42 org = helpers.NewOrgName() 43 space = helpers.NewSpaceName() 44 service = helpers.PrefixedRandomName("SERVICE") 45 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 46 47 helpers.SetupCF(org, space) 48 domain = helpers.DefaultSharedDomain() 49 }) 50 51 AfterEach(func() { 52 helpers.QuickDeleteOrg(org) 53 }) 54 55 When("the service is provided by a user", func() { 56 BeforeEach(func() { 57 Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0)) 58 }) 59 60 AfterEach(func() { 61 Eventually(helpers.CF("delete-service", serviceInstance, "-f")).Should(Exit(0)) 62 }) 63 64 When("the service is bound to an app", func() { 65 BeforeEach(func() { 66 helpers.WithHelloWorldApp(func(appDir string) { 67 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 68 }) 69 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 70 }) 71 72 It("unbinds the service", func() { 73 Eventually(helpers.CF("services")).Should(SatisfyAll( 74 Exit(0), 75 Say("%s.*%s", serviceInstance, appName)), 76 ) 77 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 78 Eventually(helpers.CF("services")).Should(SatisfyAll( 79 Exit(0), 80 Not(Say("%s.*%s", serviceInstance, appName)), 81 )) 82 }) 83 }) 84 85 When("the service is not bound to an app", func() { 86 BeforeEach(func() { 87 helpers.WithHelloWorldApp(func(appDir string) { 88 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 89 }) 90 }) 91 92 It("returns a warning and continues", func() { 93 session := helpers.CF("unbind-service", appName, serviceInstance) 94 Eventually(session).Should(Say("OK")) 95 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 96 Eventually(session).Should(Exit(0)) 97 }) 98 }) 99 100 When("the service does not exist", func() { 101 BeforeEach(func() { 102 helpers.WithHelloWorldApp(func(appDir string) { 103 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 104 }) 105 }) 106 107 It("fails to unbind the service", func() { 108 session := helpers.CF("unbind-service", appName, "does-not-exist") 109 Eventually(session).Should(Say("FAILED")) 110 Eventually(session.Err).Should(Say("Service instance %s not found", "does-not-exist")) 111 Eventually(session).Should(Exit(1)) 112 }) 113 }) 114 115 When("the app does not exist", func() { 116 It("fails to unbind the service", func() { 117 session := helpers.CF("unbind-service", "does-not-exist", serviceInstance) 118 Eventually(session).Should(Say("FAILED")) 119 Eventually(session.Err).Should(Say("App %s not found", "does-not-exist")) 120 Eventually(session).Should(Exit(1)) 121 }) 122 }) 123 }) 124 125 When("the service is provided by a broker", func() { 126 When("the unbinding is asynchronous", func() { 127 BeforeEach(func() { 128 helpers.SkipIfVersionLessThan(ccversion.MinVersionAsyncBindingsV2) 129 broker = helpers.NewAsynchServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 130 broker.Push() 131 broker.Configure(true) 132 broker.Create() 133 134 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 135 136 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 137 helpers.WithHelloWorldApp(func(appDir string) { 138 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 139 }) 140 141 Eventually(func() *Session { 142 session := helpers.CF("service", serviceInstance) 143 return session.Wait() 144 }, time.Minute*5, time.Second*5).Should(Say("create succeeded")) 145 146 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 147 client, err := helpers.CreateCCV2Client() 148 Expect(err).ToNot(HaveOccurred()) 149 helpers.PollLastOperationUntilSuccess(client, appName, serviceInstance) 150 }) 151 152 AfterEach(func() { 153 broker.Destroy() 154 }) 155 156 It("returns that the unbind is in progress", func() { 157 session := helpers.CF("unbind-service", appName, serviceInstance) 158 Eventually(session).Should(Say("OK")) 159 Eventually(session).Should(Say("Unbinding in progress. Use 'cf service %s' to check operation status.", serviceInstance)) 160 Eventually(session).Should(Exit(0)) 161 }) 162 }) 163 164 When("the unbinding is blocking", func() { 165 BeforeEach(func() { 166 broker = helpers.CreateBroker(domain, service, servicePlan) 167 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 168 }) 169 170 AfterEach(func() { 171 broker.Destroy() 172 }) 173 174 When("the service is bound to an app", func() { 175 BeforeEach(func() { 176 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 177 helpers.WithHelloWorldApp(func(appDir string) { 178 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 179 }) 180 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 181 }) 182 183 It("unbinds the service", func() { 184 Eventually(helpers.CF("services")).Should(SatisfyAll( 185 Exit(0), 186 Say("%s.*%s", serviceInstance, appName)), 187 ) 188 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 189 Eventually(helpers.CF("services")).Should(SatisfyAll( 190 Exit(0), 191 Not(Say("%s.*%s", serviceInstance, appName)), 192 )) 193 }) 194 }) 195 196 When("the service is not bound to an app", func() { 197 BeforeEach(func() { 198 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 199 helpers.WithHelloWorldApp(func(appDir string) { 200 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 201 }) 202 }) 203 204 It("returns a warning and continues", func() { 205 session := helpers.CF("unbind-service", appName, serviceInstance) 206 Eventually(session).Should(Say("OK")) 207 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 208 Eventually(session).Should(Exit(0)) 209 }) 210 }) 211 212 When("the service does not exist", func() { 213 BeforeEach(func() { 214 helpers.WithHelloWorldApp(func(appDir string) { 215 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 216 }) 217 }) 218 219 It("fails to unbind the service", func() { 220 session := helpers.CF("unbind-service", appName, serviceInstance) 221 Eventually(session).Should(Say("FAILED")) 222 Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstance)) 223 Eventually(session).Should(Exit(1)) 224 }) 225 }) 226 227 When("the app does not exist", func() { 228 BeforeEach(func() { 229 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 230 }) 231 232 It("fails to unbind the service", func() { 233 session := helpers.CF("unbind-service", appName, serviceInstance) 234 Eventually(session).Should(Say("FAILED")) 235 Eventually(session.Err).Should(Say("App %s not found", appName)) 236 Eventually(session).Should(Exit(1)) 237 }) 238 }) 239 }) 240 }) 241 }) 242 })