github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/update_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("update-service command", func() {
    13  	When("the environment is not setup correctly", func() {
    14  		It("fails with the appropriate errors", func() {
    15  			// the upgrade flag is passed here to exercise a particular code path before refactoring
    16  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "update-service", "foo", "--upgrade")
    17  		})
    18  	})
    19  
    20  	When("an api is targeted, the user is logged in, and an org and space are targeted", func() {
    21  		var (
    22  			orgName string
    23  		)
    24  
    25  		BeforeEach(func() {
    26  			orgName = helpers.NewOrgName()
    27  			var spaceName = helpers.NewSpaceName()
    28  			helpers.SetupCF(orgName, spaceName)
    29  		})
    30  
    31  		AfterEach(func() {
    32  			helpers.QuickDeleteOrg(orgName)
    33  		})
    34  
    35  		When("there are no service instances", func() {
    36  			When("upgrading", func() {
    37  				It("displays an informative error before prompting and exits 1", func() {
    38  					session := helpers.CF("update-service", "non-existent-service", "--upgrade")
    39  					Eventually(session.Err).Should(Say("Service instance non-existent-service not found"))
    40  					Eventually(session).Should(Exit(1))
    41  				})
    42  			})
    43  		})
    44  
    45  		When("providing other arguments while upgrading", func() {
    46  			It("displays an informative error message and exits 1", func() {
    47  				session := helpers.CF("update-service", "irrelevant", "--upgrade", "-c", "{\"hello\": \"world\"}")
    48  				Eventually(session.Err).Should(Say("Incorrect Usage: The following arguments cannot be used together: --upgrade, -t, -c, -p"))
    49  				Eventually(session).Should(Say("FAILED"))
    50  				Eventually(session).Should(Say("USAGE:"))
    51  				Eventually(session).Should(Exit(1))
    52  			})
    53  		})
    54  
    55  		When("there is a service instance", func() {
    56  			var (
    57  				service             string
    58  				servicePlan         string
    59  				broker              helpers.ServiceBroker
    60  				serviceInstanceName string
    61  				username            string
    62  			)
    63  
    64  			BeforeEach(func() {
    65  				var domain = helpers.DefaultSharedDomain()
    66  				service = helpers.PrefixedRandomName("SERVICE")
    67  				servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
    68  				broker = helpers.CreateBroker(domain, service, servicePlan)
    69  
    70  				Eventually(helpers.CF("service-access")).Should(Say(service))
    71  				Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
    72  
    73  				serviceInstanceName = helpers.PrefixedRandomName("SI")
    74  				Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0))
    75  
    76  				username, _ = helpers.GetCredentials()
    77  			})
    78  
    79  			AfterEach(func() {
    80  				Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0))
    81  				broker.Destroy()
    82  			})
    83  
    84  			When("updating to a service plan that does not exist", func() {
    85  				It("displays an informative error message, exits 1", func() {
    86  					session := helpers.CF("update-service", serviceInstanceName, "-p", "non-existing-service-plan")
    87  					Eventually(session).Should(Say("Plan does not exist for the %s service", service))
    88  					Eventually(session).Should(Exit(1))
    89  				})
    90  			})
    91  
    92  			When("updating to the same service plan (no-op)", func() {
    93  				It("displays an informative success message, exits 0", func() {
    94  					session := helpers.CF("update-service", serviceInstanceName, "-p", servicePlan)
    95  					Eventually(session).Should(Say("Updating service instance %s as %s...", serviceInstanceName, username))
    96  					Eventually(session).Should(Say("OK"))
    97  					Eventually(session).Should(Exit(0))
    98  				})
    99  			})
   100  
   101  			When("upgrading", func() {
   102  				var buffer *Buffer
   103  
   104  				BeforeEach(func() {
   105  					buffer = NewBuffer()
   106  				})
   107  
   108  				When("cancelling the update", func() {
   109  					BeforeEach(func() {
   110  						_, err := buffer.Write([]byte("n\n"))
   111  						Expect(err).ToNot(HaveOccurred())
   112  					})
   113  
   114  					It("does not proceed", func() {
   115  						session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade")
   116  						Eventually(session).Should(Say("You are about to update %s", serviceInstanceName))
   117  						Eventually(session).Should(Say("Warning: This operation may be long running and will block further operations on the service until complete."))
   118  						Eventually(session).Should(Say("Really update service %s\\? \\[yN\\]:", serviceInstanceName))
   119  						Eventually(session).Should(Say("Update cancelled"))
   120  						Eventually(session).Should(Exit(0))
   121  					})
   122  				})
   123  
   124  				When("proceeding with the update", func() {
   125  					BeforeEach(func() {
   126  						helpers.SkipIfVersionLessThan(ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2)
   127  						_, err := buffer.Write([]byte("y\n"))
   128  						Expect(err).ToNot(HaveOccurred())
   129  					})
   130  
   131  					It("updates the service", func() {
   132  						session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade")
   133  
   134  						By("displaying an informative message")
   135  						Eventually(session).Should(Say("You are about to update %s", serviceInstanceName))
   136  						Eventually(session).Should(Say("Warning: This operation may be long running and will block further operations on the service until complete."))
   137  						Eventually(session).Should(Say("Really update service %s\\? \\[yN\\]:", serviceInstanceName))
   138  						Eventually(session).Should(Exit(0))
   139  
   140  						By("requesting an upgrade from the platform")
   141  						session = helpers.CF("service", serviceInstanceName)
   142  						Eventually(session).Should(Say("status:\\s+update succeeded"))
   143  					})
   144  				})
   145  			})
   146  		})
   147  	})
   148  })