github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_restart_command_test.go (about) 1 package experimental 2 3 import ( 4 "github.com/liamawhite/cli-with-i18n/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.Out).Should(Say("NAME:")) 31 Eventually(session.Out).Should(Say("v3-restart - Stop all instances of the app, then start them again\\. This causes downtime\\.")) 32 Eventually(session.Out).Should(Say("USAGE:")) 33 Eventually(session.Out).Should(Say("cf v3-restart APP_NAME")) 34 Eventually(session.Out).Should(Say("ENVIRONMENT:")) 35 Eventually(session.Out).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.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-restart", 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-restart", 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-restart", 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-restart", 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-restart", 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-restart", 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 helpers.WithHelloWorldApp(func(appDir string) { 159 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 160 }) 161 }) 162 163 Context("when the app is running", func() { 164 It("stops then restarts the app", func() { 165 userName, _ := helpers.GetCredentials() 166 167 session := helpers.CF("v3-restart", appName) 168 Eventually(session.Out).Should(Say("Stopping app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 169 Eventually(session.Out).Should(Say("OK")) 170 Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 171 Eventually(session.Out).Should(Say("OK")) 172 173 Eventually(session).Should(Exit(0)) 174 }) 175 }) 176 177 Context("when the app is stopped", func() { 178 BeforeEach(func() { 179 Eventually(helpers.CF("v3-stop", appName)).Should(Exit(0)) 180 }) 181 182 It("starts the app", func() { 183 userName, _ := helpers.GetCredentials() 184 185 session := helpers.CF("v3-restart", appName) 186 Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 187 Eventually(session.Out).Should(Say("OK")) 188 189 Eventually(session).Should(Exit(0)) 190 }) 191 }) 192 193 }) 194 195 Context("when the app does not exist", func() { 196 It("displays app not found and exits 1", func() { 197 invalidAppName := helpers.PrefixedRandomName("invalid-app") 198 session := helpers.CF("v3-restart", invalidAppName) 199 200 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 201 Eventually(session.Out).Should(Say("FAILED")) 202 203 Eventually(session).Should(Exit(1)) 204 }) 205 }) 206 }) 207 })