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