github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 It("fails with the appropriate errors", func() { 24 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "unbind-service", "app-name", "service-name") 25 }) 26 }) 27 28 Context("when the environment is setup correctly", func() { 29 var ( 30 org string 31 space string 32 service string 33 servicePlan string 34 broker helpers.ServiceBroker 35 domain string 36 ) 37 38 BeforeEach(func() { 39 org = helpers.NewOrgName() 40 space = helpers.NewSpaceName() 41 service = helpers.PrefixedRandomName("SERVICE") 42 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 43 44 setupCF(org, space) 45 domain = defaultSharedDomain() 46 }) 47 48 AfterEach(func() { 49 helpers.QuickDeleteOrg(org) 50 }) 51 52 Context("when the service is provided by a user", func() { 53 BeforeEach(func() { 54 Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0)) 55 }) 56 57 AfterEach(func() { 58 Eventually(helpers.CF("delete-service", serviceInstance, "-f")).Should(Exit(0)) 59 }) 60 61 Context("when the service is bound to an app", func() { 62 BeforeEach(func() { 63 helpers.WithHelloWorldApp(func(appDir string) { 64 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 65 }) 66 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 67 }) 68 69 It("unbinds the service", func() { 70 Eventually(helpers.CF("services")).Should(SatisfyAll( 71 Exit(0), 72 Say("%s.*%s", serviceInstance, appName)), 73 ) 74 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 75 Eventually(helpers.CF("services")).Should(SatisfyAll( 76 Exit(0), 77 Not(Say("%s.*%s", serviceInstance, appName)), 78 )) 79 }) 80 }) 81 82 Context("when the service is not bound to an app", func() { 83 BeforeEach(func() { 84 helpers.WithHelloWorldApp(func(appDir string) { 85 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 86 }) 87 }) 88 89 It("returns a warning and continues", func() { 90 session := helpers.CF("unbind-service", appName, serviceInstance) 91 Eventually(session).Should(Say("OK")) 92 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 93 Eventually(session).Should(Exit(0)) 94 }) 95 }) 96 97 Context("when the service does not exist", func() { 98 BeforeEach(func() { 99 helpers.WithHelloWorldApp(func(appDir string) { 100 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 101 }) 102 }) 103 104 It("fails to unbind the service", func() { 105 session := helpers.CF("unbind-service", appName, "does-not-exist") 106 Eventually(session).Should(Say("FAILED")) 107 Eventually(session.Err).Should(Say("Service instance %s not found", "does-not-exist")) 108 Eventually(session).Should(Exit(1)) 109 }) 110 }) 111 112 Context("when the app does not exist", func() { 113 It("fails to unbind the service", func() { 114 session := helpers.CF("unbind-service", "does-not-exist", serviceInstance) 115 Eventually(session).Should(Say("FAILED")) 116 Eventually(session.Err).Should(Say("App %s not found", "does-not-exist")) 117 Eventually(session).Should(Exit(1)) 118 }) 119 }) 120 }) 121 122 Context("when the service is provided by a broker", func() { 123 BeforeEach(func() { 124 broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 125 broker.Push() 126 broker.Configure(true) 127 broker.Create() 128 129 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 130 }) 131 132 AfterEach(func() { 133 broker.Destroy() 134 }) 135 136 Context("when the service is bound to an app", func() { 137 BeforeEach(func() { 138 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 139 helpers.WithHelloWorldApp(func(appDir string) { 140 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 141 }) 142 Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0)) 143 }) 144 145 It("unbinds the service", func() { 146 Eventually(helpers.CF("services")).Should(SatisfyAll( 147 Exit(0), 148 Say("%s.*%s", serviceInstance, appName)), 149 ) 150 Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0)) 151 Eventually(helpers.CF("services")).Should(SatisfyAll( 152 Exit(0), 153 Not(Say("%s.*%s", serviceInstance, appName)), 154 )) 155 }) 156 }) 157 158 Context("when the service is not bound to an app", func() { 159 BeforeEach(func() { 160 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 161 helpers.WithHelloWorldApp(func(appDir string) { 162 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0)) 163 }) 164 }) 165 166 It("returns a warning and continues", func() { 167 session := helpers.CF("unbind-service", appName, serviceInstance) 168 Eventually(session).Should(Say("OK")) 169 Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName)) 170 Eventually(session).Should(Exit(0)) 171 }) 172 }) 173 174 Context("when the service does not exist", func() { 175 BeforeEach(func() { 176 helpers.WithHelloWorldApp(func(appDir string) { 177 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 178 }) 179 }) 180 181 It("fails to unbind the service", func() { 182 session := helpers.CF("unbind-service", appName, serviceInstance) 183 Eventually(session).Should(Say("FAILED")) 184 Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstance)) 185 Eventually(session).Should(Exit(1)) 186 }) 187 }) 188 189 Context("when the app does not exist", func() { 190 BeforeEach(func() { 191 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0)) 192 }) 193 194 It("fails to unbind the service", func() { 195 session := helpers.CF("unbind-service", appName, serviceInstance) 196 Eventually(session).Should(Say("FAILED")) 197 Eventually(session.Err).Should(Say("App %s not found", appName)) 198 Eventually(session).Should(Exit(1)) 199 }) 200 }) 201 }) 202 }) 203 })