github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_restart_command_test.go (about) 1 package experimental 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 . "github.com/onsi/gomega/ghttp" 10 ) 11 12 var _ = Describe("v3-restart command", func() { 13 var ( 14 orgName string 15 spaceName string 16 appName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 appName = helpers.PrefixedRandomName("app") 23 }) 24 25 Describe("help", func() { 26 Context("when --help flag is set", func() { 27 It("displays command usage to output", func() { 28 session := helpers.CF("v3-restart", "--help") 29 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say("v3-restart - Stop all instances of the app, then start them again\\. This causes downtime\\.")) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say("cf v3-restart APP_NAME")) 34 Eventually(session).Should(Say("ENVIRONMENT:")) 35 Eventually(session).Should(Say("CF_STARTUP_TIMEOUT=5\\s+Max wait time for app instance startup, in minutes")) 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-restart") 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-restart", 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-restart", 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-restart", 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-restart", 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-restart", 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-restart", 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-restart", 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 helpers.WithHelloWorldApp(func(appDir string) { 165 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 166 }) 167 }) 168 169 Context("when the app is running", func() { 170 It("stops then restarts the app", func() { 171 userName, _ := helpers.GetCredentials() 172 173 session := helpers.CF("v3-restart", appName) 174 Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 175 Eventually(session).Should(Say("OK")) 176 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 177 Eventually(session).Should(Say("OK")) 178 179 Eventually(session).Should(Exit(0)) 180 }) 181 }) 182 183 Context("when the app is stopped", func() { 184 BeforeEach(func() { 185 Eventually(helpers.CF("v3-stop", appName)).Should(Exit(0)) 186 }) 187 188 It("starts the app", func() { 189 userName, _ := helpers.GetCredentials() 190 191 session := helpers.CF("v3-restart", appName) 192 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 193 Eventually(session).Should(Say("OK")) 194 195 Eventually(session).Should(Exit(0)) 196 }) 197 }) 198 199 }) 200 201 Context("when the app does not exist", func() { 202 It("displays app not found and exits 1", func() { 203 invalidAppName := helpers.PrefixedRandomName("invalid-app") 204 session := helpers.CF("v3-restart", invalidAppName) 205 206 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 207 Eventually(session).Should(Say("FAILED")) 208 209 Eventually(session).Should(Exit(1)) 210 }) 211 }) 212 }) 213 })