github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/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/integration/helpers" 10 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 Context("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 Context("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 Context("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 setupCF(orgName, spaceName) 56 }) 57 58 AfterEach(func() { 59 helpers.QuickDeleteOrg(orgName) 60 }) 61 62 Context("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 Context("when the app does exist", func() { 74 var ( 75 domainName string 76 appName string 77 ) 78 79 Context("when the app is started", func() { 80 BeforeEach(func() { 81 appName = helpers.PrefixedRandomName("app") 82 domainName = defaultSharedDomain() 83 helpers.WithHelloWorldApp(func(appDir string) { 84 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 85 }) 86 }) 87 88 It("stops the app and starts it again", func() { 89 userName, _ := helpers.GetCredentials() 90 session := helpers.CF("restart", appName) 91 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 92 Eventually(session).Should(Say("Stopping app\\.\\.\\.")) 93 Consistently(session).ShouldNot(Say("Staging app and tracing logs\\.\\.\\.")) 94 Eventually(session).Should(Say("Waiting for app to start\\.\\.\\.")) 95 Eventually(session).Should(Exit(0)) 96 }) 97 }) 98 99 Context("when the app is stopped", func() { 100 Context("when the app has been staged", func() { 101 BeforeEach(func() { 102 appName = helpers.PrefixedRandomName("app") 103 domainName = defaultSharedDomain() 104 helpers.WithHelloWorldApp(func(appDir string) { 105 manifestContents := []byte(fmt.Sprintf(` 106 --- 107 applications: 108 - name: %s 109 memory: 128M 110 instances: 2 111 disk_quota: 128M 112 routes: 113 - route: %s.%s 114 `, appName, appName, domainName)) 115 manifestPath := filepath.Join(appDir, "manifest.yml") 116 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 117 Expect(err).ToNot(HaveOccurred()) 118 119 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 120 }) 121 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 122 }) 123 124 It("displays the app information with instances table", func() { 125 userName, _ := helpers.GetCredentials() 126 session := helpers.CF("restart", appName) 127 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 128 Consistently(session).ShouldNot(Say("Stopping app\\.\\.\\.")) 129 Consistently(session).ShouldNot(Say("Staging app and tracing logs\\.\\.\\.")) 130 Eventually(session).Should(Say("Waiting for app to start\\.\\.\\.")) 131 132 Eventually(session).Should(Say("name:\\s+%s", appName)) 133 Eventually(session).Should(Say("requested state:\\s+started")) 134 Eventually(session).Should(Say("instances:\\s+2/2")) 135 Eventually(session).Should(Say("usage:\\s+128M x 2 instances")) 136 Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName)) 137 Eventually(session).Should(Say("last uploaded:")) 138 Eventually(session).Should(Say("stack:\\s+cflinuxfs2")) 139 Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack")) 140 Eventually(session).Should(Say("start command:")) 141 142 Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details")) 143 Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 144 Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 145 Eventually(session).Should(Exit(0)) 146 }) 147 }) 148 149 Context("when the app does *not* stage properly because the app was not detected by any buildpacks", func() { 150 BeforeEach(func() { 151 appName = helpers.PrefixedRandomName("app") 152 domainName = defaultSharedDomain() 153 helpers.WithHelloWorldApp(func(appDir string) { 154 err := os.Remove(filepath.Join(appDir, "Staticfile")) 155 Expect(err).ToNot(HaveOccurred()) 156 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 157 }) 158 }) 159 160 It("fails and displays the staging failure message", func() { 161 userName, _ := helpers.GetCredentials() 162 session := helpers.CF("restart", appName) 163 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 164 Eventually(session).Should(Say("Staging app and tracing logs\\.\\.\\.")) 165 166 // The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection. 167 Eventually(session.Err).Should(Say("Error staging application: An app was not successfully detected by any available buildpack")) 168 Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`)) 169 Eventually(session).Should(Exit(1)) 170 }) 171 }) 172 173 Context("when the app stages properly", func() { 174 Context("when the app does *not* start properly", func() { 175 BeforeEach(func() { 176 appName = helpers.PrefixedRandomName("app") 177 helpers.WithHelloWorldApp(func(appDir string) { 178 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start", "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(0)) 179 }) 180 }) 181 182 It("fails and displays the start failure message", func() { 183 userName, _ := helpers.GetCredentials() 184 session := helpers.CF("restart", appName) 185 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 186 187 Eventually(session.Err).Should(Say("Start unsuccessful")) 188 Eventually(session.Err).Should(Say("TIP: use 'cf logs .* --recent' for more information")) 189 Eventually(session).Should(Exit(1)) 190 }) 191 }) 192 193 Context("when the app starts properly", func() { 194 BeforeEach(func() { 195 Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0)) 196 Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0)) 197 Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0)) 198 appName = helpers.PrefixedRandomName("app") 199 domainName = defaultSharedDomain() 200 helpers.WithHelloWorldApp(func(appDir string) { 201 manifestContents := []byte(fmt.Sprintf(` 202 --- 203 applications: 204 - name: %s 205 memory: 128M 206 instances: 2 207 disk_quota: 128M 208 routes: 209 - route: %s.%s 210 `, appName, appName, domainName)) 211 manifestPath := filepath.Join(appDir, "manifest.yml") 212 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 213 Expect(err).ToNot(HaveOccurred()) 214 215 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 216 }) 217 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 218 }) 219 220 It("displays the app logs and information with instances table", func() { 221 userName, _ := helpers.GetCredentials() 222 session := helpers.CF("restart", appName) 223 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 224 Consistently(session).ShouldNot(Say("Stopping app\\.\\.\\.")) 225 226 // Display Staging Logs 227 Eventually(session).Should(Say("Staging app and tracing logs\\.\\.\\.")) 228 Eventually(session).Should(Say("Uploading droplet\\.\\.\\.")) 229 Eventually(session).Should(Say("Waiting for app to start\\.\\.\\.")) 230 231 Eventually(session).Should(Say("name:\\s+%s", appName)) 232 Eventually(session).Should(Say("requested state:\\s+started")) 233 Eventually(session).Should(Say("instances:\\s+2/2")) 234 Eventually(session).Should(Say("isolation segment:\\s+%s", RealIsolationSegment)) 235 Eventually(session).Should(Say("usage:\\s+128M x 2 instances")) 236 Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName)) 237 Eventually(session).Should(Say("last uploaded:")) 238 Eventually(session).Should(Say("stack:\\s+cflinuxfs2")) 239 Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack")) 240 Eventually(session).Should(Say("start command:")) 241 242 Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details")) 243 244 Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 245 Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 246 Eventually(session).Should(Exit(0)) 247 }) 248 }) 249 }) 250 }) 251 }) 252 }) 253 })