github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_start_application_command_test.go (about) 1 package experimental 2 3 import ( 4 "regexp" 5 6 "github.com/liamawhite/cli-with-i18n/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.Out).Should(Say("NAME:")) 33 Eventually(session.Out).Should(Say("v3-start - Start an app")) 34 Eventually(session.Out).Should(Say("USAGE:")) 35 Eventually(session.Out).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.Out).Should(Say("NAME:")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 Context("when the environment is not setup correctly", func() { 53 Context("when no API endpoint is set", func() { 54 BeforeEach(func() { 55 helpers.UnsetAPI() 56 }) 57 58 It("fails with no API endpoint set message", func() { 59 session := helpers.CF("v3-start", appName) 60 Eventually(session).Should(Say("FAILED")) 61 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 62 Eventually(session).Should(Exit(1)) 63 }) 64 }) 65 66 Context("when the v3 api does not exist", func() { 67 var server *Server 68 69 BeforeEach(func() { 70 server = helpers.StartAndTargetServerWithoutV3API() 71 }) 72 73 AfterEach(func() { 74 server.Close() 75 }) 76 77 It("fails with error message that the minimum version is not met", func() { 78 session := helpers.CF("v3-start", appName) 79 Eventually(session).Should(Say("FAILED")) 80 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 85 Context("when the v3 api version is lower than the minimum version", func() { 86 var server *Server 87 88 BeforeEach(func() { 89 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 90 }) 91 92 AfterEach(func() { 93 server.Close() 94 }) 95 96 It("fails with error message that the minimum version is not met", func() { 97 session := helpers.CF("v3-start", appName) 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 Context("when not logged in", func() { 105 BeforeEach(func() { 106 helpers.LogoutCF() 107 }) 108 109 It("fails with not logged in message", func() { 110 session := helpers.CF("v3-start", appName) 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 117 Context("when there is no org set", func() { 118 BeforeEach(func() { 119 helpers.LogoutCF() 120 helpers.LoginCF() 121 }) 122 123 It("fails with no org targeted error message", func() { 124 session := helpers.CF("v3-start", appName) 125 Eventually(session.Out).Should(Say("FAILED")) 126 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 127 Eventually(session).Should(Exit(1)) 128 }) 129 }) 130 131 Context("when there is no space set", func() { 132 BeforeEach(func() { 133 helpers.LogoutCF() 134 helpers.LoginCF() 135 helpers.TargetOrg(ReadOnlyOrg) 136 }) 137 138 It("fails with no space targeted error message", func() { 139 session := helpers.CF("v3-start", appName) 140 Eventually(session.Out).Should(Say("FAILED")) 141 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 142 Eventually(session).Should(Exit(1)) 143 }) 144 }) 145 }) 146 147 Context("when the environment is set up correctly", func() { 148 BeforeEach(func() { 149 setupCF(orgName, spaceName) 150 }) 151 152 AfterEach(func() { 153 helpers.QuickDeleteOrg(orgName) 154 }) 155 156 Context("when the app exists", func() { 157 BeforeEach(func() { 158 var packageGUID string 159 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 160 161 helpers.WithHelloWorldApp(func(dir string) { 162 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-create-package", appName) 163 Eventually(pkgSession).Should(Exit(0)) 164 regex, err := regexp.Compile(`package guid: (.+)`) 165 Expect(err).ToNot(HaveOccurred()) 166 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 167 Expect(matches).To(HaveLen(2)) 168 169 packageGUID = matches[1] 170 }) 171 172 stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID) 173 Eventually(stageSession).Should(Exit(0)) 174 175 regex, err := regexp.Compile(`droplet guid:\s+(.+)`) 176 Expect(err).ToNot(HaveOccurred()) 177 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 178 Expect(matches).To(HaveLen(2)) 179 180 dropletGUID := matches[1] 181 setDropletSession := helpers.CF("v3-set-droplet", appName, "--droplet-guid", dropletGUID) 182 Eventually(setDropletSession).Should(Exit(0)) 183 }) 184 185 It("starts the app", func() { 186 userName, _ := helpers.GetCredentials() 187 188 session := helpers.CF("v3-start", appName) 189 Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 190 Eventually(session.Out).Should(Say("OK")) 191 192 Eventually(session).Should(Exit(0)) 193 }) 194 195 Context("when the app is already started", func() { 196 BeforeEach(func() { 197 Eventually(helpers.CF("v3-start", appName)).Should(Exit(0)) 198 }) 199 200 It("displays app already started and exits 0", func() { 201 session := helpers.CF("v3-start", appName) 202 203 Eventually(session.Err).Should(Say("App %s is already started", appName)) 204 Eventually(session.Out).Should(Say("OK")) 205 206 Eventually(session).Should(Exit(0)) 207 }) 208 }) 209 }) 210 211 Context("when the app does not exist", func() { 212 It("displays app not found and exits 1", func() { 213 invalidAppName := "invalid-app-name" 214 session := helpers.CF("v3-start", invalidAppName) 215 216 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 217 Eventually(session.Out).Should(Say("FAILED")) 218 219 Eventually(session).Should(Exit(1)) 220 }) 221 }) 222 }) 223 })