github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/restage_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 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("restage command", func() { 17 Describe("help", func() { 18 When("--help flag is set", func() { 19 It("Displays command usage to output", func() { 20 session := helpers.CF("restage", "--help") 21 22 Eventually(session).Should(Say("NAME:")) 23 Eventually(session).Should(Say(`restage - Stage the app's latest package into a droplet and restart the app with this new droplet and updated configuration \(environment variables, service bindings, buildpack, stack, etc.\).`)) 24 Eventually(session).ShouldNot(Say(`This action will cause app downtime.`)) 25 Eventually(session).Should(Say("USAGE:")) 26 Eventually(session).Should(Say("cf restage APP_NAME")) 27 Eventually(session).Should(Say("This command will cause downtime unless you use '--strategy rolling'.")) 28 Eventually(session).Should(Say("EXAMPLES:")) 29 Eventually(session).Should(Say("cf restage APP_NAME")) 30 Eventually(session).Should(Say("cf restage APP_NAME --strategy rolling")) 31 Eventually(session).Should(Say("cf restage APP_NAME --strategy rolling --no-wait")) 32 Eventually(session).Should(Say("ALIAS:")) 33 Eventually(session).Should(Say("rg")) 34 Eventually(session).Should(Say("OPTIONS:")) 35 Eventually(session).Should(Say("--strategy Deployment strategy, either rolling or null")) 36 Eventually(session).Should(Say("--no-wait Exit when the first instance of the web process is healthy")) 37 Eventually(session).Should(Say("ENVIRONMENT:")) 38 Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`)) 39 Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`)) 40 Eventually(session).Should(Say("SEE ALSO:")) 41 Eventually(session).Should(Say("restart")) 42 Eventually(session).Should(Exit(0)) 43 }) 44 }) 45 }) 46 47 When("the environment is not setup correctly", func() { 48 It("fails with the appropriate errors", func() { 49 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "restage", "app-name") 50 }) 51 }) 52 53 When("the environment is set up correctly", func() { 54 var ( 55 orgName string 56 spaceName string 57 ) 58 59 BeforeEach(func() { 60 orgName = helpers.NewOrgName() 61 spaceName = helpers.NewSpaceName() 62 63 helpers.SetupCF(orgName, spaceName) 64 }) 65 66 AfterEach(func() { 67 helpers.QuickDeleteOrg(orgName) 68 }) 69 70 When("the app does not exist", func() { 71 It("tells the user that the app is not found and exits 1", func() { 72 appName := helpers.PrefixedRandomName("app") 73 session := helpers.CF("restage", appName) 74 75 Eventually(session).Should(Say("FAILED")) 76 Eventually(session.Err).Should(Say("App '%s' not found", appName)) 77 Eventually(session).Should(Exit(1)) 78 }) 79 }) 80 81 When("the app does exist", func() { 82 var ( 83 domainName string 84 appName string 85 ) 86 When("there are no packages for the app to restage", func() { 87 BeforeEach(func() { 88 appName = helpers.PrefixedRandomName("app") 89 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 90 }) 91 92 It("fails and displays the package not found failure message", func() { 93 userName, _ := helpers.GetCredentials() 94 session := helpers.CF("restage", appName) 95 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 96 97 Eventually(session.Err).Should(Say(`App '%s' has no eligible packages\.`, appName)) 98 Eventually(session.Err).Should(Say(`TIP: Use 'cf packages %s' to list packages in your app. Use 'cf create-package' to create one\.`, appName)) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 103 When("there is an error in staging the app", func() { 104 BeforeEach(func() { 105 appName = helpers.PrefixedRandomName("app") 106 domainName = helpers.DefaultSharedDomain() 107 helpers.WithHelloWorldApp(func(appDir string) { 108 err := os.Remove(filepath.Join(appDir, "Staticfile")) 109 Expect(err).ToNot(HaveOccurred()) 110 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(1)) 111 }) 112 }) 113 114 It("fails and displays the staging failure message", func() { 115 userName, _ := helpers.GetCredentials() 116 session := helpers.CF("restage", appName) 117 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 118 119 // The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection. 120 Eventually(session.Err).Should(Say("Error staging application: NoAppDetectedError - An app was not successfully detected by any available buildpack")) 121 Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`)) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 126 When("the app does *not* start properly", func() { 127 BeforeEach(func() { 128 appName = helpers.PrefixedRandomName("app") 129 helpers.WithHelloWorldApp(func(appDir string) { 130 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(1)) 131 }) 132 }) 133 134 It("fails and displays the start failure message", func() { 135 userName, _ := helpers.GetCredentials() 136 session := helpers.CF("restage", appName) 137 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 138 139 Eventually(session.Err).Should(Say("Start unsuccessful")) 140 Eventually(session.Err).Should(Say("TIP: use 'cf logs .* --recent' for more information")) 141 Eventually(session).Should(Exit(1)) 142 }) 143 144 When("strategy rolling is given", func() { 145 It("fails and displays the deployment failure message", func() { 146 userName, _ := helpers.GetCredentials() 147 session := helpers.CustomCF(helpers.CFEnv{ 148 EnvVars: map[string]string{"CF_STARTUP_TIMEOUT": "0.1"}, 149 }, "restage", appName, "--strategy", "rolling") 150 Consistently(session.Err).ShouldNot(Say(`This action will cause app downtime\.`)) 151 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 152 Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) 153 Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`)) 154 Eventually(session.Err).Should(Say(`Start app timeout`)) 155 Eventually(session.Err).Should(Say(`TIP: Application must be listening on the right port\.`)) 156 Eventually(session).Should(Say("FAILED")) 157 Eventually(session).Should(Exit(1)) 158 }) 159 }) 160 }) 161 162 When("the app stages and starts properly", func() { 163 BeforeEach(func() { 164 appName = helpers.PrefixedRandomName("app") 165 domainName = helpers.DefaultSharedDomain() 166 helpers.WithHelloWorldApp(func(appDir string) { 167 manifestContents := []byte(fmt.Sprintf(` 168 --- 169 applications: 170 - name: %s 171 memory: 128M 172 instances: 2 173 disk_quota: 128M 174 routes: 175 - route: %s.%s 176 `, appName, appName, domainName)) 177 manifestPath := filepath.Join(appDir, "manifest.yml") 178 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 179 Expect(err).ToNot(HaveOccurred()) 180 181 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 182 }) 183 }) 184 185 It("uses the multiprocess display", func() { 186 userName, _ := helpers.GetCredentials() 187 session := helpers.CF("restage", appName) 188 Eventually(session.Err).Should(Say(`This action will cause app downtime\.`)) 189 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 190 191 helpers.ConfirmStagingLogs(session) 192 193 Eventually(session).Should(Say(`name:\s+%s`, appName)) 194 Eventually(session).Should(Say(`requested state:\s+started`)) 195 Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName)) 196 Eventually(session).Should(Say(`last uploaded:\s+%s`, helpers.ReadableDateTimeRegex)) 197 Eventually(session).Should(Say(`stack:\s+cflinuxfs`)) 198 Eventually(session).Should(Say(`buildpacks:\s+\n`)) 199 Eventually(session).Should(Say(`staticfile_buildpack\s+\d+.\d+.\d+\s+`)) 200 Eventually(session).Should(Say(`type:\s+web`)) 201 Eventually(session).Should(Say(`sidecars:`)) 202 Eventually(session).Should(Say(`instances:\s+\d/2`)) 203 Eventually(session).Should(Say(`memory usage:\s+128M`)) 204 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`)) 205 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 206 Eventually(session).Should(Exit(0)) 207 }) 208 209 When("strategy rolling is given", func() { 210 It("creates a deploy", func() { 211 userName, _ := helpers.GetCredentials() 212 session := helpers.CF("restage", appName, "--strategy=rolling") 213 Consistently(session.Err).ShouldNot(Say(`This action will cause app downtime\.`)) 214 Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 215 Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) 216 Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`)) 217 Eventually(session).Should(Say(`name:\s+%s`, appName)) 218 Eventually(session).Should(Say(`requested state:\s+started`)) 219 Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName)) 220 Eventually(session).Should(Say(`last uploaded:\s+%s`, helpers.ReadableDateTimeRegex)) 221 Eventually(session).Should(Say(`stack:\s+cflinuxfs`)) 222 Eventually(session).Should(Say(`buildpacks:\s+\n`)) 223 Eventually(session).Should(Say(`staticfile_buildpack\s+\d+.\d+.\d+\s+`)) 224 Eventually(session).Should(Say(`type:\s+web`)) 225 Eventually(session).Should(Say(`sidecars:`)) 226 Eventually(session).Should(Say(`instances:\s+\d/2`)) 227 Eventually(session).Should(Say(`memory usage:\s+128M`)) 228 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`)) 229 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 230 Eventually(session).Should(Exit(0)) 231 }) 232 }) 233 234 When("isolation segments are available", func() { 235 BeforeEach(func() { 236 Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0)) 237 Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0)) 238 Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0)) 239 }) 240 241 It("displays app isolation segment information", func() { 242 session := helpers.CF("restage", appName) 243 Eventually(session).Should(Say(`isolation segment:\s+%s`, RealIsolationSegment)) 244 }) 245 }) 246 }) 247 }) 248 }) 249 })