github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/rename_service_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 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("rename-service command", func() { 13 Describe("help", func() { 14 expectHelpMessage := func(session *Session) { 15 Expect(session).To(SatisfyAll( 16 Say(`NAME:\n`), 17 Say(`rename-service - Rename a service instance\n`), 18 Say(`\n`), 19 Say(`USAGE:\n`), 20 Say(`cf rename-service SERVICE_INSTANCE NEW_SERVICE_INSTANCE\n`), 21 Say(`\n`), 22 Say(`SEE ALSO:\n`), 23 Say(`services, update-service\n`), 24 )) 25 } 26 27 When("the --help flag is set", func() { 28 It("displays command usage to output", func() { 29 session := helpers.CF("rename-service", "--help") 30 Eventually(session).Should(Exit(0)) 31 expectHelpMessage(session) 32 }) 33 }) 34 35 When("no args are passed", func() { 36 It("displays an error message with help text and exits 1", func() { 37 session := helpers.CF("rename-service") 38 Eventually(session).Should(Exit(1)) 39 Expect(session.Err).To(Say("Incorrect Usage: the required arguments `SERVICE_INSTANCE` and `NEW_SERVICE_INSTANCE` were not provided")) 40 expectHelpMessage(session) 41 }) 42 }) 43 44 When("one arg is passed", func() { 45 It("displays an error message with help text and exits 1", func() { 46 session := helpers.CF("rename-service", "lala") 47 Eventually(session).Should(Exit(1)) 48 Expect(session.Err).To(Say("Incorrect Usage: the required argument `NEW_SERVICE_INSTANCE` was not provided")) 49 expectHelpMessage(session) 50 }) 51 }) 52 53 When("more than required number of args are passed", func() { 54 It("displays an error message with help text and exits 1", func() { 55 session := helpers.CF("rename-service", "lala", "papa", "mama") 56 Eventually(session).Should(Exit(1)) 57 Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "mama"`)) 58 expectHelpMessage(session) 59 }) 60 }) 61 62 When("an invalid flag is passed", func() { 63 It("displays an error message with help text and exits 1", func() { 64 session := helpers.CF("rename-service", "--unicorn-mode") 65 Eventually(session).Should(Exit(1)) 66 Expect(session.Err).To(Say("Incorrect Usage: unknown flag `unicorn-mode'")) 67 expectHelpMessage(session) 68 }) 69 }) 70 }) 71 72 When("environment is not set up", func() { 73 It("displays an error and exits 1", func() { 74 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "rename-service", "foo", "bar") 75 }) 76 }) 77 78 When("logged in and targeting a space", func() { 79 var ( 80 currentName string 81 newName string 82 orgName string 83 spaceName string 84 username string 85 ) 86 87 BeforeEach(func() { 88 currentName = helpers.NewServiceInstanceName() 89 newName = helpers.NewServiceInstanceName() 90 91 orgName = helpers.NewOrgName() 92 spaceName = helpers.NewSpaceName() 93 helpers.SetupCF(orgName, spaceName) 94 95 username, _ = helpers.GetCredentials() 96 }) 97 98 AfterEach(func() { 99 helpers.QuickDeleteOrg(orgName) 100 }) 101 102 When("the service instance does not exist", func() { 103 It("fails with an appropriate error", func() { 104 session := helpers.CF("rename-service", currentName, newName) 105 106 Eventually(session).Should(Exit(1)) 107 Expect(session.Err).To(Say("Service instance '%s' not found", currentName)) 108 }) 109 }) 110 111 testRename := func() { 112 It("renames the service instance", func() { 113 originalGUID := helpers.ServiceInstanceGUID(currentName) 114 115 session := helpers.CF("rename-service", currentName, newName) 116 117 Eventually(session).Should(Exit(0)) 118 Expect(session.Out).To(SatisfyAll( 119 Say(`Renaming service %s to %s in org %s / space %s as %s...\n`, currentName, newName, orgName, spaceName, username), 120 Say(`OK\n`), 121 )) 122 Expect(session.Err.Contents()).To(BeEmpty()) 123 124 Expect(helpers.ServiceInstanceGUID(newName)).To(Equal(originalGUID)) 125 }) 126 127 When("the service instance name is taken", func() { 128 BeforeEach(func() { 129 Eventually(helpers.CF("create-user-provided-service", newName)).Should(Exit(0)) 130 }) 131 132 It("fails and explains why", func() { 133 session := helpers.CF("rename-service", currentName, newName) 134 135 Eventually(session).Should(Exit(1)) 136 Expect(session.Out).To(SatisfyAll( 137 Say(`Renaming service %s to %s in org %s / space %s as %s...\n`, currentName, newName, orgName, spaceName, username), 138 Say(`FAILED\n`), 139 )) 140 Expect(session.Err).To(Say(`The service instance name is taken: %s\.?\n`, newName)) 141 }) 142 }) 143 } 144 145 Context("user-provided service instance", func() { 146 BeforeEach(func() { 147 Eventually(helpers.CF("create-user-provided-service", currentName)).Should(Exit(0)) 148 }) 149 150 testRename() 151 }) 152 153 Context("managed service instance", func() { 154 var broker *servicebrokerstub.ServiceBrokerStub 155 156 BeforeEach(func() { 157 broker = servicebrokerstub.EnableServiceAccess() 158 159 helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), currentName) 160 }) 161 162 AfterEach(func() { 163 broker.Forget() 164 }) 165 166 testRename() 167 }) 168 }) 169 })