github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/isolated/unbind_service_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker"
     7  
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("unbind-service command", func() {
    17  	var (
    18  		serviceInstance string
    19  		appName         string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		serviceInstance = helpers.PrefixedRandomName("si")
    24  		appName = helpers.PrefixedRandomName("app")
    25  	})
    26  
    27  	When("the environment is not setup correctly", func() {
    28  		It("fails with the appropriate errors", func() {
    29  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "unbind-service", "app-name", "service-name")
    30  		})
    31  	})
    32  
    33  	When("the environment is setup correctly", func() {
    34  		var (
    35  			org   string
    36  			space string
    37  		)
    38  
    39  		BeforeEach(func() {
    40  			org = helpers.NewOrgName()
    41  			space = helpers.NewSpaceName()
    42  			helpers.SetupCF(org, space)
    43  		})
    44  
    45  		AfterEach(func() {
    46  			helpers.QuickDeleteOrg(org)
    47  		})
    48  
    49  		When("the service is provided by a user", func() {
    50  			BeforeEach(func() {
    51  				Eventually(helpers.CF("create-user-provided-service", serviceInstance, "-p", "{}")).Should(Exit(0))
    52  			})
    53  
    54  			AfterEach(func() {
    55  				Eventually(helpers.CF("delete-service", serviceInstance, "-f")).Should(Exit(0))
    56  			})
    57  
    58  			When("the service is bound to an app", func() {
    59  				BeforeEach(func() {
    60  					helpers.WithHelloWorldApp(func(appDir string) {
    61  						Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    62  					})
    63  					Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0))
    64  				})
    65  
    66  				It("unbinds the service", func() {
    67  					Eventually(helpers.CF("services")).Should(SatisfyAll(
    68  						Exit(0),
    69  						Say("%s.*%s", serviceInstance, appName)),
    70  					)
    71  					Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0))
    72  					Eventually(helpers.CF("services")).Should(SatisfyAll(
    73  						Exit(0),
    74  						Not(Say("%s.*%s", serviceInstance, appName)),
    75  					))
    76  				})
    77  			})
    78  
    79  			When("the service is not bound to an app", func() {
    80  				BeforeEach(func() {
    81  					helpers.WithHelloWorldApp(func(appDir string) {
    82  						Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0))
    83  					})
    84  				})
    85  
    86  				It("returns a warning and continues", func() {
    87  					session := helpers.CF("unbind-service", appName, serviceInstance)
    88  					Eventually(session).Should(Say("OK"))
    89  					Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName))
    90  					Eventually(session).Should(Exit(0))
    91  				})
    92  			})
    93  
    94  			When("the service does not exist", func() {
    95  				BeforeEach(func() {
    96  					helpers.WithHelloWorldApp(func(appDir string) {
    97  						Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    98  					})
    99  				})
   100  
   101  				It("fails to unbind the service", func() {
   102  					session := helpers.CF("unbind-service", appName, "does-not-exist")
   103  					Eventually(session).Should(Say("FAILED"))
   104  					Eventually(session.Err).Should(Say("Service instance %s not found", "does-not-exist"))
   105  					Eventually(session).Should(Exit(1))
   106  				})
   107  			})
   108  
   109  			When("the app does not exist", func() {
   110  				It("fails to unbind the service", func() {
   111  					session := helpers.CF("unbind-service", "does-not-exist", serviceInstance)
   112  					Eventually(session).Should(Say("FAILED"))
   113  					Eventually(session.Err).Should(Say("App '%s' not found", "does-not-exist"))
   114  					Eventually(session).Should(Exit(1))
   115  				})
   116  			})
   117  		})
   118  
   119  		When("the service is provided by a broker", func() {
   120  			var (
   121  				service     string
   122  				servicePlan string
   123  				broker      *fakeservicebroker.FakeServiceBroker
   124  			)
   125  
   126  			When("the unbinding is asynchronous", func() {
   127  				BeforeEach(func() {
   128  					helpers.SkipIfVersionLessThan(ccversion.MinVersionAsyncBindingsV2)
   129  
   130  					broker = fakeservicebroker.New().WithAsyncBehaviour().EnsureBrokerIsAvailable()
   131  					service = broker.ServiceName()
   132  					servicePlan = broker.ServicePlanName()
   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 = fakeservicebroker.New().EnsureBrokerIsAvailable()
   167  					service = broker.ServiceName()
   168  					servicePlan = broker.ServicePlanName()
   169  
   170  					Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   171  				})
   172  
   173  				AfterEach(func() {
   174  					broker.Destroy()
   175  				})
   176  
   177  				When("the service is bound to an app", func() {
   178  					BeforeEach(func() {
   179  						Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0))
   180  						helpers.WithHelloWorldApp(func(appDir string) {
   181  							Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   182  						})
   183  						Eventually(helpers.CF("bind-service", appName, serviceInstance)).Should(Exit(0))
   184  					})
   185  
   186  					It("unbinds the service", func() {
   187  						Eventually(helpers.CF("services")).Should(SatisfyAll(
   188  							Exit(0),
   189  							Say("%s.*%s", serviceInstance, appName)),
   190  						)
   191  						Eventually(helpers.CF("unbind-service", appName, serviceInstance)).Should(Exit(0))
   192  						Eventually(helpers.CF("services")).Should(SatisfyAll(
   193  							Exit(0),
   194  							Not(Say("%s.*%s", serviceInstance, appName)),
   195  						))
   196  					})
   197  				})
   198  
   199  				When("the service is not bound to an app", func() {
   200  					BeforeEach(func() {
   201  						Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0))
   202  						helpers.WithHelloWorldApp(func(appDir string) {
   203  							Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "--no-route")).Should(Exit(0))
   204  						})
   205  					})
   206  
   207  					It("returns a warning and continues", func() {
   208  						session := helpers.CF("unbind-service", appName, serviceInstance)
   209  						Eventually(session).Should(Say("OK"))
   210  						Eventually(session.Err).Should(Say("Binding between %s and %s did not exist", serviceInstance, appName))
   211  						Eventually(session).Should(Exit(0))
   212  					})
   213  				})
   214  
   215  				When("the service does not exist", func() {
   216  					BeforeEach(func() {
   217  						helpers.WithHelloWorldApp(func(appDir string) {
   218  							Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   219  						})
   220  					})
   221  
   222  					It("fails to unbind the service", func() {
   223  						session := helpers.CF("unbind-service", appName, serviceInstance)
   224  						Eventually(session).Should(Say("FAILED"))
   225  						Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstance))
   226  						Eventually(session).Should(Exit(1))
   227  					})
   228  				})
   229  
   230  				When("the app does not exist", func() {
   231  					BeforeEach(func() {
   232  						Eventually(helpers.CF("create-service", service, servicePlan, serviceInstance)).Should(Exit(0))
   233  					})
   234  
   235  					It("fails to unbind the service", func() {
   236  						session := helpers.CF("unbind-service", appName, serviceInstance)
   237  						Eventually(session).Should(Say("FAILED"))
   238  						Eventually(session.Err).Should(Say("App '%s' not found", appName))
   239  						Eventually(session).Should(Exit(1))
   240  					})
   241  				})
   242  			})
   243  		})
   244  	})
   245  })