github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/start_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 7 "regexp" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 const ( 16 PushCommandName = "push" 17 ) 18 19 var _ = Describe("start command", func() { 20 var ( 21 orgName string 22 spaceName string 23 appName string 24 ) 25 26 BeforeEach(func() { 27 orgName = helpers.NewOrgName() 28 spaceName = helpers.NewSpaceName() 29 appName = helpers.PrefixedRandomName("app") 30 }) 31 32 Describe("help", func() { 33 When("--help flag is set", func() { 34 It("appears in cf help -a", func() { 35 session := helpers.CF("help", "-a") 36 Eventually(session).Should(Exit(0)) 37 Expect(session).To(HaveCommandInCategoryWithDescription("start", "APPS", "Start an app")) 38 }) 39 40 It("Displays command usage to output", func() { 41 session := helpers.CF("start", "--help") 42 43 Eventually(session).Should(Say("NAME:")) 44 Eventually(session).Should(Say("start - Start an app")) 45 Eventually(session).Should(Say("USAGE:")) 46 Eventually(session).Should(Say("cf start APP_NAME")) 47 Eventually(session).Should(Say("ALIAS:")) 48 Eventually(session).Should(Say("st")) 49 Eventually(session).Should(Say("ENVIRONMENT:")) 50 Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`)) 51 Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`)) 52 Eventually(session).Should(Say("SEE ALSO:")) 53 Eventually(session).Should(Say("apps, logs, restart, run-task, scale, ssh, stop")) 54 55 Eventually(session).Should(Exit(0)) 56 }) 57 }) 58 }) 59 60 When("the app name is not provided", func() { 61 It("tells the user that the app name is required, prints help text, and exits 1", func() { 62 session := helpers.CF("start") 63 64 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 65 Eventually(session).Should(Say("NAME:")) 66 Eventually(session).Should(Exit(1)) 67 }) 68 }) 69 70 When("the environment is not setup correctly", func() { 71 It("fails with the appropriate errors", func() { 72 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "start", appName) 73 }) 74 }) 75 76 When("the environment is set up correctly", func() { 77 BeforeEach(func() { 78 helpers.SetupCF(orgName, spaceName) 79 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 80 }) 81 82 AfterEach(func() { 83 helpers.QuickDeleteOrg(orgName) 84 }) 85 86 When("the app exists", func() { 87 When("the app does not need to be staged", func() { 88 BeforeEach(func() { 89 var packageGUID string 90 91 mapRouteSession := helpers.CF("map-route", appName, helpers.DefaultSharedDomain(), "-n", appName) 92 Eventually(mapRouteSession).Should(Exit(0)) 93 94 helpers.WithHelloWorldApp(func(dir string) { 95 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "create-package", appName) 96 Eventually(pkgSession).Should(Exit(0)) 97 regex := regexp.MustCompile(`Package with guid '(.+)' has been created.`) 98 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 99 Expect(matches).To(HaveLen(2)) 100 101 packageGUID = matches[1] 102 }) 103 104 stageSession := helpers.CF("stage", appName, "--package-guid", packageGUID) 105 Eventually(stageSession).Should(Exit(0)) 106 107 regex := regexp.MustCompile(`droplet guid:\s+(.+)`) 108 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 109 Expect(matches).To(HaveLen(2)) 110 111 dropletGUID := matches[1] 112 setDropletSession := helpers.CF("set-droplet", appName, "--droplet-guid", dropletGUID) 113 Eventually(setDropletSession).Should(Exit(0)) 114 }) 115 116 It("starts the app", func() { 117 userName, _ := helpers.GetCredentials() 118 119 session := helpers.CF("start", appName) 120 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 121 Eventually(session).Should(Say(`Waiting for app to start\.\.\.`)) 122 Eventually(session).Should(Say(`name:\s+%s`, appName)) 123 Eventually(session).Should(Say(`requested state:\s+started`)) 124 Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain())) 125 Eventually(session).Should(Say(`type:\s+web`)) 126 Eventually(session).Should(Say(`instances:\s+1/1`)) 127 Eventually(session).Should(Say(`memory usage:\s+32M`)) 128 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`)) 129 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 130 131 Eventually(session).Should(Exit(0)) 132 }) 133 134 When("the app is already started", func() { 135 BeforeEach(func() { 136 Eventually(helpers.CF("start", appName)).Should(Exit(0)) 137 }) 138 139 It("displays app already started and exits 0", func() { 140 session := helpers.CF("start", appName) 141 142 Eventually(session).Should(Say(`App '%s' is already started\.`, appName)) 143 Eventually(session).Should(Say("OK")) 144 145 Eventually(session).Should(Exit(0)) 146 }) 147 }) 148 }) 149 150 When("the app needs to be staged", func() { 151 var packageGUID = "" 152 BeforeEach(func() { 153 helpers.WithHelloWorldApp(func(dir string) { 154 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 155 Eventually(session).Should(Say(`\s+name:\s+%s`, appName)) 156 Eventually(session).Should(Say(`requested state:\s+started`)) 157 Eventually(session).Should(Exit(0)) 158 }) 159 160 session := helpers.CF("stop", appName) 161 Eventually(session).Should(Say("OK")) 162 163 helpers.WithBananaPantsApp(func(dir string) { 164 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "create-package", appName) 165 Eventually(pkgSession).Should(Exit(0)) 166 regex := regexp.MustCompile(`Package with guid '(.+)' has been created.`) 167 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 168 Expect(matches).To(HaveLen(2)) 169 170 packageGUID = matches[1] 171 }) 172 }) 173 174 It("stages and starts the app", func() { 175 session := helpers.CF("start", appName) 176 177 Eventually(session).Should(Say(`Staging app and tracing logs`)) 178 helpers.ConfirmStagingLogs(session) 179 180 Eventually(session).Should(Say(`Waiting for app to start\.\.\.`)) 181 Eventually(session).Should(Say(`name:\s+%s`, appName)) 182 Eventually(session).Should(Say(`requested state:\s+started`)) 183 Eventually(session).Should(Say(`type:\s+web`)) 184 Eventually(session).Should(Say(`instances:\s+1/1`)) 185 Eventually(session).Should(Say(`memory usage:\s+32M`)) 186 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`)) 187 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 188 189 Eventually(session).Should(Exit(0)) 190 Expect(session.Err).ToNot(Say(`timeout connecting to log server, no log will be shown`)) 191 192 Expect(helpers.GetPackageFirstDroplet(packageGUID)).To(Equal(helpers.GetAppDroplet(helpers.AppGUID(appName)))) 193 }) 194 }) 195 196 When("the app cannot be started or staged", func() { 197 It("gives an error", func() { 198 session := helpers.CF("start", appName) 199 200 Eventually(session.Err).Should(Say(`App can not start with out a package to stage or a droplet to run.`)) 201 Eventually(session).Should(Say("FAILED")) 202 203 Eventually(session).Should(Exit(1)) 204 }) 205 }) 206 }) 207 208 When("the app does not exist", func() { 209 It("displays app not found and exits 1", func() { 210 invalidAppName := "invalid-app-name" 211 session := helpers.CF("start", invalidAppName) 212 213 Eventually(session.Err).Should(Say(`App '%s' not found\.`, invalidAppName)) 214 Eventually(session).Should(Say("FAILED")) 215 216 Eventually(session).Should(Exit(1)) 217 }) 218 }) 219 }) 220 })