github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_start_application_command_test.go (about) 1 package experimental 2 3 import ( 4 "regexp" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("v3-start-application command", func() { 15 var ( 16 orgName string 17 spaceName string 18 appName string 19 ) 20 21 BeforeEach(func() { 22 orgName = helpers.NewOrgName() 23 spaceName = helpers.NewSpaceName() 24 appName = helpers.PrefixedRandomName("app") 25 }) 26 27 Describe("help", func() { 28 Context("when --help flag is set", func() { 29 It("Displays command usage to output", func() { 30 session := helpers.CF("v3-start", "--help") 31 32 Eventually(session).Should(Say("NAME:")) 33 Eventually(session).Should(Say("v3-start - Start an app")) 34 Eventually(session).Should(Say("USAGE:")) 35 Eventually(session).Should(Say("cf v3-start APP_NAME")) 36 37 Eventually(session).Should(Exit(0)) 38 }) 39 }) 40 }) 41 42 Context("when the app name is not provided", func() { 43 It("tells the user that the app name is required, prints help text, and exits 1", func() { 44 session := helpers.CF("v3-start") 45 46 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 47 Eventually(session).Should(Say("NAME:")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 It("displays the experimental warning", func() { 53 session := helpers.CF("v3-start", appName) 54 Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 55 Eventually(session).Should(Exit()) 56 }) 57 58 Context("when the environment is not setup correctly", func() { 59 Context("when no API endpoint is set", func() { 60 BeforeEach(func() { 61 helpers.UnsetAPI() 62 }) 63 64 It("fails with no API endpoint set message", func() { 65 session := helpers.CF("v3-start", appName) 66 Eventually(session).Should(Say("FAILED")) 67 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 68 Eventually(session).Should(Exit(1)) 69 }) 70 }) 71 72 Context("when the v3 api does not exist", func() { 73 var server *Server 74 75 BeforeEach(func() { 76 server = helpers.StartAndTargetServerWithoutV3API() 77 }) 78 79 AfterEach(func() { 80 server.Close() 81 }) 82 83 It("fails with error message that the minimum version is not met", func() { 84 session := helpers.CF("v3-start", appName) 85 Eventually(session).Should(Say("FAILED")) 86 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 87 Eventually(session).Should(Exit(1)) 88 }) 89 }) 90 91 Context("when the v3 api version is lower than the minimum version", func() { 92 var server *Server 93 94 BeforeEach(func() { 95 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 96 }) 97 98 AfterEach(func() { 99 server.Close() 100 }) 101 102 It("fails with error message that the minimum version is not met", func() { 103 session := helpers.CF("v3-start", appName) 104 Eventually(session).Should(Say("FAILED")) 105 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 106 Eventually(session).Should(Exit(1)) 107 }) 108 }) 109 110 Context("when not logged in", func() { 111 BeforeEach(func() { 112 helpers.LogoutCF() 113 }) 114 115 It("fails with not logged in message", func() { 116 session := helpers.CF("v3-start", appName) 117 Eventually(session).Should(Say("FAILED")) 118 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 119 Eventually(session).Should(Exit(1)) 120 }) 121 }) 122 123 Context("when there is no org set", func() { 124 BeforeEach(func() { 125 helpers.LogoutCF() 126 helpers.LoginCF() 127 }) 128 129 It("fails with no org targeted error message", func() { 130 session := helpers.CF("v3-start", appName) 131 Eventually(session).Should(Say("FAILED")) 132 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 133 Eventually(session).Should(Exit(1)) 134 }) 135 }) 136 137 Context("when there is no space set", func() { 138 BeforeEach(func() { 139 helpers.LogoutCF() 140 helpers.LoginCF() 141 helpers.TargetOrg(ReadOnlyOrg) 142 }) 143 144 It("fails with no space targeted error message", func() { 145 session := helpers.CF("v3-start", appName) 146 Eventually(session).Should(Say("FAILED")) 147 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 148 Eventually(session).Should(Exit(1)) 149 }) 150 }) 151 }) 152 153 Context("when the environment is set up correctly", func() { 154 BeforeEach(func() { 155 setupCF(orgName, spaceName) 156 }) 157 158 AfterEach(func() { 159 helpers.QuickDeleteOrg(orgName) 160 }) 161 162 Context("when the app exists", func() { 163 BeforeEach(func() { 164 var packageGUID string 165 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 166 167 helpers.WithHelloWorldApp(func(dir string) { 168 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-create-package", appName) 169 Eventually(pkgSession).Should(Exit(0)) 170 regex, err := regexp.Compile(`package guid: (.+)`) 171 Expect(err).ToNot(HaveOccurred()) 172 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 173 Expect(matches).To(HaveLen(2)) 174 175 packageGUID = matches[1] 176 }) 177 178 stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID) 179 Eventually(stageSession).Should(Exit(0)) 180 181 regex, err := regexp.Compile(`droplet guid:\s+(.+)`) 182 Expect(err).ToNot(HaveOccurred()) 183 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 184 Expect(matches).To(HaveLen(2)) 185 186 dropletGUID := matches[1] 187 setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID) 188 Eventually(setDropletSession).Should(Exit(0)) 189 }) 190 191 It("starts the app", func() { 192 userName, _ := helpers.GetCredentials() 193 194 session := helpers.CF("v3-start", appName) 195 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 196 Eventually(session).Should(Say("OK")) 197 198 Eventually(session).Should(Exit(0)) 199 }) 200 201 Context("when the app is already started", func() { 202 BeforeEach(func() { 203 Eventually(helpers.CF("v3-start", appName)).Should(Exit(0)) 204 }) 205 206 It("displays app already started and exits 0", func() { 207 session := helpers.CF("v3-start", appName) 208 209 Eventually(session.Err).Should(Say("App %s is already started", appName)) 210 Eventually(session).Should(Say("OK")) 211 212 Eventually(session).Should(Exit(0)) 213 }) 214 }) 215 }) 216 217 Context("when the app does not exist", func() { 218 It("displays app not found and exits 1", func() { 219 invalidAppName := "invalid-app-name" 220 session := helpers.CF("v3-start", invalidAppName) 221 222 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 223 Eventually(session).Should(Say("FAILED")) 224 225 Eventually(session).Should(Exit(1)) 226 }) 227 }) 228 }) 229 })