github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("update-service command", func() { 14 Describe("help", func() { 15 When("--help flag is set", func() { 16 It("displays command usage to output", func() { 17 session := helpers.CF("update-service", "--help") 18 Eventually(session).Should(Say("NAME:")) 19 Eventually(session).Should(Say(`\s+update-service - Update a service instance`)) 20 Eventually(session).Should(Say(`USAGE:`)) 21 Eventually(session).Should(Say(`\s+cf update-service SERVICE_INSTANCE \[-p NEW_PLAN\] \[-c PARAMETERS_AS_JSON\] \[-t TAGS\] \[--upgrade\]`)) 22 Eventually(session).Should(Say(`\s+Optionally provide service-specific configuration parameters in a valid JSON object in-line:`)) 23 Eventually(session).Should(Say(`\s+cf update-service SERVICE_INSTANCE -c '{\"name\":\"value\",\"name\":\"value\"}'`)) 24 Eventually(session).Should(Say(`\s+Optionally provide a file containing service-specific configuration parameters in a valid JSON object\.`)) 25 Eventually(session).Should(Say(`\s+The path to the parameters file can be an absolute or relative path to a file:`)) 26 Eventually(session).Should(Say(`\s+cf update-service SERVICE_INSTANCE -c PATH_TO_FILE`)) 27 Eventually(session).Should(Say(`\s+Example of valid JSON object:`)) 28 Eventually(session).Should(Say(`\s+{`)) 29 Eventually(session).Should(Say(`\s+\"cluster_nodes\": {`)) 30 Eventually(session).Should(Say(`\s+\"count\": 5,`)) 31 Eventually(session).Should(Say(`\s+\"memory_mb\": 1024`)) 32 Eventually(session).Should(Say(`\s+}`)) 33 Eventually(session).Should(Say(`\s+}`)) 34 Eventually(session).Should(Say(`\s+ Optionally provide a list of comma-delimited tags that will be written to the VCAP_SERVICES environment variable for any bound applications.`)) 35 Eventually(session).Should(Say(`EXAMPLES:`)) 36 Eventually(session).Should(Say(`\s+cf update-service mydb -p gold`)) 37 Eventually(session).Should(Say(`\s+cf update-service mydb -c '{\"ram_gb\":4}'`)) 38 Eventually(session).Should(Say(`\s+cf update-service mydb -c ~/workspace/tmp/instance_config.json`)) 39 Eventually(session).Should(Say(`\s+cf update-service mydb -t "list, of, tags"`)) 40 Eventually(session).Should(Say(`\s+cf update-service mydb --upgrade`)) 41 Eventually(session).Should(Say(`\s+cf update-service mydb --upgrade --force`)) 42 Eventually(session).Should(Say(`OPTIONS:`)) 43 Eventually(session).Should(Say(`\s+-c\s+Valid JSON object containing service-specific configuration parameters, provided either in-line or in a file\. For a list of supported configuration parameters, see documentation for the particular service offering\.`)) 44 Eventually(session).Should(Say(`\s+-p\s+Change service plan for a service instance`)) 45 Eventually(session).Should(Say(`\s+-t\s+User provided tags`)) 46 Eventually(session).Should(Say(`\s+--upgrade, -u\s+Upgrade the service instance to the latest version of the service plan available. It cannot be combined with flags: -c, -p, -t.`)) 47 Eventually(session).Should(Say(`\s+--force, -f\s+Force the upgrade to the latest available version of the service plan. It can only be used with: -u, --upgrade.`)) 48 Eventually(session).Should(Say(`SEE ALSO:`)) 49 Eventually(session).Should(Say(`\s+rename-service, services, update-user-provided-service`)) 50 Eventually(session).Should(Exit(0)) 51 }) 52 }) 53 }) 54 55 When("the environment is not setup correctly", func() { 56 BeforeEach(func() { 57 helpers.SkipIfVersionLessThan(ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2) 58 }) 59 60 It("fails with the appropriate errors", func() { 61 // the upgrade flag is passed here to exercise a particular code path before refactoring 62 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "update-service", "foo", "--upgrade") 63 }) 64 }) 65 66 When("an api is targeted, the user is logged in, and an org and space are targeted", func() { 67 var ( 68 orgName string 69 ) 70 71 BeforeEach(func() { 72 orgName = helpers.NewOrgName() 73 var spaceName = helpers.NewSpaceName() 74 helpers.SetupCF(orgName, spaceName) 75 }) 76 77 AfterEach(func() { 78 helpers.QuickDeleteOrg(orgName) 79 }) 80 81 When("there are no service instances", func() { 82 When("upgrading", func() { 83 BeforeEach(func() { 84 helpers.SkipIfVersionLessThan(ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2) 85 }) 86 87 It("displays an informative error before prompting and exits 1", func() { 88 session := helpers.CF("update-service", "non-existent-service", "--upgrade") 89 Eventually(session.Err).Should(Say("Service instance non-existent-service not found")) 90 Eventually(session).Should(Exit(1)) 91 }) 92 }) 93 }) 94 95 When("providing other arguments while upgrading", func() { 96 It("displays an informative error message and exits 1", func() { 97 session := helpers.CF("update-service", "irrelevant", "--upgrade", "-c", "{\"hello\": \"world\"}") 98 Eventually(session.Err).Should(Say("Incorrect Usage: The following arguments cannot be used together: --upgrade, -t, -c, -p")) 99 Eventually(session).Should(Say("FAILED")) 100 Eventually(session).Should(Say("USAGE:")) 101 Eventually(session).Should(Exit(1)) 102 }) 103 }) 104 105 When("there is a service instance", func() { 106 var ( 107 broker *fakeservicebroker.FakeServiceBroker 108 serviceInstanceName string 109 username string 110 ) 111 112 BeforeEach(func() { 113 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 114 Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0)) 115 116 serviceInstanceName = helpers.PrefixedRandomName("SI") 117 Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), serviceInstanceName)).Should(Exit(0)) 118 119 username, _ = helpers.GetCredentials() 120 }) 121 122 AfterEach(func() { 123 Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0)) 124 broker.Destroy() 125 }) 126 127 When("updating to a service plan that does not exist", func() { 128 It("displays an informative error message, exits 1", func() { 129 session := helpers.CF("update-service", serviceInstanceName, "-p", "non-existing-service-plan") 130 Eventually(session).Should(Say("Plan does not exist for the %s service", broker.ServiceName())) 131 Eventually(session).Should(Exit(1)) 132 }) 133 }) 134 135 When("updating to the same service plan (no-op)", func() { 136 It("displays an informative success message, exits 0", func() { 137 session := helpers.CF("update-service", serviceInstanceName, "-p", broker.ServicePlanName()) 138 Eventually(session).Should(Say("Updating service instance %s as %s...", serviceInstanceName, username)) 139 Eventually(session).Should(Say("OK")) 140 Eventually(session).Should(Say("No changes were made")) 141 Eventually(session).Should(Exit(0)) 142 }) 143 }) 144 145 When("upgrading", func() { 146 var buffer *Buffer 147 148 BeforeEach(func() { 149 buffer = NewBuffer() 150 }) 151 152 When("the user provides --upgrade in an unsupported CAPI version", func() { 153 BeforeEach(func() { 154 helpers.SkipIfVersionAtLeast(ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2) 155 }) 156 157 It("should report that the version of CAPI is too low", func() { 158 session := helpers.CF("update-service", serviceInstanceName, "--upgrade") 159 Eventually(session.Err).Should(Say(`Option '--upgrade' requires CF API version %s or higher. Your target is 2\.\d+\.\d+`, ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2)) 160 Eventually(session).Should(Exit(1)) 161 }) 162 }) 163 164 When("when CAPI supports service instance maintenance_info updates", func() { 165 BeforeEach(func() { 166 helpers.SkipIfVersionLessThan(ccversion.MinVersionUpdateServiceInstanceMaintenanceInfoV2) 167 }) 168 169 When("cancelling the update", func() { 170 BeforeEach(func() { 171 _, err := buffer.Write([]byte("n\n")) 172 Expect(err).ToNot(HaveOccurred()) 173 }) 174 175 It("does not proceed", func() { 176 session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade") 177 Eventually(session).Should(Say("You are about to update %s", serviceInstanceName)) 178 Eventually(session).Should(Say("Warning: This operation may be long running and will block further operations on the service until complete.")) 179 Eventually(session).Should(Say("Really update service %s\\? \\[yN\\]:", serviceInstanceName)) 180 Eventually(session).Should(Say("Update cancelled")) 181 Eventually(session).Should(Exit(0)) 182 }) 183 }) 184 185 When("proceeding with the update", func() { 186 BeforeEach(func() { 187 _, err := buffer.Write([]byte("y\n")) 188 Expect(err).ToNot(HaveOccurred()) 189 }) 190 191 When("upgrade is available", func() { 192 BeforeEach(func() { 193 broker.Services[0].Plans[0].MaintenanceInfo.Version = "9.1.2" 194 broker.Update() 195 }) 196 197 It("updates the service", func() { 198 session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade") 199 200 By("displaying an informative message") 201 Eventually(session).Should(Say("You are about to update %s", serviceInstanceName)) 202 Eventually(session).Should(Say("Warning: This operation may be long running and will block further operations on the service until complete.")) 203 Eventually(session).Should(Say("Really update service %s\\? \\[yN\\]:", serviceInstanceName)) 204 Eventually(session).Should(Say("Updating service instance %s as %s...", serviceInstanceName, username)) 205 Eventually(session).Should(Exit(0)) 206 207 By("requesting an upgrade from the platform") 208 session = helpers.CF("service", serviceInstanceName) 209 Eventually(session).Should(Say("status:\\s+update succeeded")) 210 }) 211 }) 212 213 When("no upgrade is available", func() { 214 It("does not update the service and outputs informative message", func() { 215 session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade") 216 217 Eventually(session).Should(Say("You are about to update %s", serviceInstanceName)) 218 Eventually(session).Should(Say("Warning: This operation may be long running and will block further operations on the service until complete.")) 219 Eventually(session).Should(Say("Really update service %s\\? \\[yN\\]:", serviceInstanceName)) 220 Eventually(session).Should(Say("Updating service instance %s as %s...", serviceInstanceName, username)) 221 Eventually(session.Err).Should(Say("No upgrade is available.")) 222 Eventually(session.Err).Should(Say("TIP: To find out if upgrade is available run `cf service %s`.", serviceInstanceName)) 223 Eventually(session).Should(Exit(1)) 224 }) 225 }) 226 }) 227 228 When("providing --force argument and upgrade is available", func() { 229 BeforeEach(func() { 230 broker.Services[0].Plans[0].MaintenanceInfo.Version = "9.1.2" 231 broker.Update() 232 }) 233 234 It("updates the service without prompting", func() { 235 session := helpers.CFWithStdin(buffer, "update-service", serviceInstanceName, "--upgrade", "--force") 236 237 By("displaying an informative message") 238 Eventually(session).Should(Say("Updating service instance %s as %s...", serviceInstanceName, username)) 239 Eventually(session).Should(Exit(0)) 240 241 By("requesting an upgrade from the platform") 242 session = helpers.CF("service", serviceInstanceName) 243 Eventually(session).Should(Say("status:\\s+update succeeded")) 244 }) 245 }) 246 }) 247 }) 248 }) 249 }) 250 })