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