github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/isolated/restart_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/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/integration/helpers" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gbytes" 14 . "github.com/onsi/gomega/gexec" 15 ) 16 17 var _ = Describe("restart command", func() { 18 Describe("help", func() { 19 When("--help flag is set", func() { 20 It("Displays command usage to output", func() { 21 session := helpers.CF("restart", "--help") 22 23 Eventually(session).Should(Say("NAME:")) 24 Eventually(session).Should(Say("restart - Stop all instances of the app, then start them again. This causes downtime.")) 25 Eventually(session).Should(Say("USAGE:")) 26 Eventually(session).Should(Say("cf restart APP_NAME")) 27 Eventually(session).Should(Say("ALIAS:")) 28 Eventually(session).Should(Say("rs")) 29 Eventually(session).Should(Say("ENVIRONMENT:")) 30 Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for buildpack staging, in minutes`)) 31 Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`)) 32 Eventually(session).Should(Say("SEE ALSO:")) 33 Eventually(session).Should(Say("restage, restart-app-instance")) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 }) 38 39 When("the environment is not setup correctly", func() { 40 It("fails with the appropriate errors", func() { 41 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "restart", "app-name") 42 }) 43 }) 44 45 When("the environment is set up correctly", func() { 46 var ( 47 orgName string 48 spaceName string 49 ) 50 51 BeforeEach(func() { 52 orgName = helpers.NewOrgName() 53 spaceName = helpers.NewSpaceName() 54 55 helpers.SetupCF(orgName, spaceName) 56 }) 57 58 AfterEach(func() { 59 helpers.QuickDeleteOrg(orgName) 60 }) 61 62 When("the app does not exist", func() { 63 It("tells the user that the start is not found and exits 1", func() { 64 appName := helpers.PrefixedRandomName("app") 65 session := helpers.CF("restart", appName) 66 67 Eventually(session).Should(Say("FAILED")) 68 Eventually(session.Err).Should(Say("App %s not found", appName)) 69 Eventually(session).Should(Exit(1)) 70 }) 71 }) 72 73 When("the app does exist", func() { 74 var ( 75 domainName string 76 appName string 77 ) 78 79 BeforeEach(func() { 80 appName = helpers.PrefixedRandomName("app") 81 domainName = helpers.DefaultSharedDomain() 82 }) 83 84 When("the app is started", func() { 85 BeforeEach(func() { 86 helpers.WithHelloWorldApp(func(appDir string) { 87 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 88 }) 89 }) 90 91 It("stops the app and starts it again", func() { 92 userName, _ := helpers.GetCredentials() 93 session := helpers.CF("restart", appName) 94 Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 95 Eventually(session).Should(Say(`Stopping app\.\.\.`)) 96 Consistently(session).ShouldNot(Say(`Staging app and tracing logs\.\.\.`)) 97 Eventually(session).Should(Say(`Waiting for app to start\.\.\.`)) 98 Eventually(session).Should(Exit(0)) 99 }) 100 }) 101 102 When("the app is stopped", func() { 103 When("the app has been staged", func() { 104 BeforeEach(func() { 105 helpers.WithHelloWorldApp(func(appDir string) { 106 manifestContents := []byte(fmt.Sprintf(` 107 --- 108 applications: 109 - name: %s 110 memory: 128M 111 instances: 2 112 disk_quota: 128M 113 routes: 114 - route: %s.%s 115 `, appName, appName, domainName)) 116 manifestPath := filepath.Join(appDir, "manifest.yml") 117 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 118 Expect(err).ToNot(HaveOccurred()) 119 120 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 121 }) 122 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 123 }) 124 125 Describe("version dependent display", func() { 126 When("CC API >= 3.27.0", func() { 127 BeforeEach(func() { 128 helpers.SkipIfVersionLessThan(ccversion.MinVersionApplicationFlowV3) 129 }) 130 131 It("uses the multiprocess display", func() { 132 userName, _ := helpers.GetCredentials() 133 134 session := helpers.CF("start", appName) 135 136 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 137 138 Eventually(session).Should(Say(`name:\s+%s`, appName)) 139 Eventually(session).Should(Say(`requested state:\s+started`)) 140 Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName)) 141 Eventually(session).Should(Say(`last uploaded:\s+\w{3} \d{1,2} \w{3} \d{2}:\d{2}:\d{2} \w{3} \d{4}`)) 142 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 143 Eventually(session).Should(Say(`buildpacks:\s+staticfile`)) 144 Eventually(session).Should(Say(`type:\s+web`)) 145 Eventually(session).Should(Say(`instances:\s+\d/2`)) 146 Eventually(session).Should(Say(`memory usage:\s+128M`)) 147 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`)) 148 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 149 150 Eventually(session).Should(Exit(0)) 151 }) 152 153 }) 154 155 When("CC API < 3.27.0", func() { 156 BeforeEach(func() { 157 helpers.SkipIfVersionAtLeast(ccversion.MinVersionApplicationFlowV3) 158 }) 159 160 It("displays the app logs and information with instances table", func() { 161 userName, _ := helpers.GetCredentials() 162 session := helpers.CF("start", appName) 163 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 164 Consistently(session).ShouldNot(Say(`Staging app and tracing logs\.\.\.`)) 165 166 Eventually(session).Should(Say(`Waiting for app to start\.\.\.`)) 167 168 Eventually(session).Should(Say(`name:\s+%s`, appName)) 169 Eventually(session).Should(Say(`requested state:\s+started`)) 170 Eventually(session).Should(Say(`instances:\s+2/2`)) 171 Eventually(session).Should(Say(`usage:\s+128M x 2 instances`)) 172 Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, domainName)) 173 Eventually(session).Should(Say("last uploaded:")) 174 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 175 Eventually(session).Should(Say(`buildpack:\s+staticfile`)) 176 Eventually(session).Should(Say("start command:")) 177 178 Eventually(session).Should(Say(`state\s+since\s+cpu\s+memory\s+disk\s+details`)) 179 Eventually(session).Should(Say(`#0\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 180 Eventually(session).Should(Say(`#1\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 181 Eventually(session).Should(Exit(0)) 182 }) 183 }) 184 }) 185 }) 186 187 When("the app does *not* stage properly because the app was not detected by any buildpacks", func() { 188 BeforeEach(func() { 189 helpers.WithHelloWorldApp(func(appDir string) { 190 err := os.Remove(filepath.Join(appDir, "Staticfile")) 191 Expect(err).ToNot(HaveOccurred()) 192 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 193 }) 194 }) 195 196 It("fails and displays the staging failure message", func() { 197 userName, _ := helpers.GetCredentials() 198 session := helpers.CF("restart", appName) 199 Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 200 Eventually(session).Should(Say(`Staging app and tracing logs\.\.\.`)) 201 202 // The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection. 203 Eventually(session.Err).Should(Say("Error staging application: An app was not successfully detected by any available buildpack")) 204 Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`)) 205 Eventually(session).Should(Exit(1)) 206 }) 207 }) 208 209 When("the app stages properly", func() { 210 When("the app does *not* start properly", func() { 211 BeforeEach(func() { 212 appName = helpers.PrefixedRandomName("app") 213 helpers.WithHelloWorldApp(func(appDir string) { 214 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start", "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(0)) 215 }) 216 }) 217 218 It("fails and displays the start failure message", func() { 219 userName, _ := helpers.GetCredentials() 220 session := helpers.CF("restart", appName) 221 Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 222 223 Eventually(session.Err).Should(Say("Start unsuccessful")) 224 Eventually(session.Err).Should(Say("TIP: use 'cf logs .* --recent' for more information")) 225 Eventually(session).Should(Exit(1)) 226 }) 227 }) 228 229 When("the app starts properly", func() { 230 BeforeEach(func() { 231 helpers.WithHelloWorldApp(func(appDir string) { 232 manifestContents := []byte(fmt.Sprintf(` 233 --- 234 applications: 235 - name: %s 236 memory: 128M 237 instances: 2 238 disk_quota: 128M 239 routes: 240 - route: %s.%s 241 `, appName, appName, domainName)) 242 manifestPath := filepath.Join(appDir, "manifest.yml") 243 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 244 Expect(err).ToNot(HaveOccurred()) 245 246 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 247 }) 248 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 249 }) 250 251 It("displays the app logs and information with instances table", func() { 252 userName, _ := helpers.GetCredentials() 253 session := helpers.CF("restart", appName) 254 Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 255 Consistently(session).ShouldNot(Say(`Stopping app\.\.\.`)) 256 257 helpers.ConfirmStagingLogs(session) 258 259 When("CC API >= 3.27.0", func() { 260 helpers.SkipIfVersionLessThan(ccversion.MinVersionApplicationFlowV3) 261 Eventually(session).Should(Say(`name:\s+%s`, appName)) 262 Eventually(session).Should(Say(`memory usage:\s+128M`)) 263 Eventually(session).Should(Exit(0)) 264 }) 265 266 When("CC API < 3.27.0", func() { 267 helpers.SkipIfVersionAtLeast(ccversion.MinVersionApplicationFlowV3) 268 269 It("displays the app logs and information with instances table", func() { 270 Eventually(session).Should(Say(`name:\s+%s`, appName)) 271 Eventually(session).Should(Say(`usage:\s+128M x 2 instances`)) 272 Eventually(session).Should(Exit(0)) 273 }) 274 }) 275 276 }) 277 }) 278 279 When("isolation segments are available", func() { 280 BeforeEach(func() { 281 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 282 283 Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0)) 284 Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0)) 285 Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0)) 286 287 helpers.WithHelloWorldApp(func(appDir string) { 288 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 289 }) 290 }) 291 292 It("displays the isolation segment information", func() { 293 session := helpers.CF("restart", appName) 294 295 Eventually(session).Should(Say(`isolation segment:\s+%s`, RealIsolationSegment)) 296 Eventually(session).Should(Exit(0)) 297 }) 298 }) 299 }) 300 }) 301 }) 302 }) 303 })