github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/experimental/v3_set_health_check_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-set-health-check 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-set-health-check", "--help") 29 30 Eventually(session).Should(Say("NAME:")) 31 Eventually(session).Should(Say("v3-set-health-check - Change type of health check performed on an app's process")) 32 Eventually(session).Should(Say("USAGE:")) 33 Eventually(session).Should(Say(`cf v3-set-health-check APP_NAME \(process \| port \| http \[--endpoint PATH\]\) \[--process PROCESS\] \[--invocation-timeout INVOCATION_TIMEOUT\]`)) 34 35 Eventually(session).Should(Say("EXAMPLES:")) 36 Eventually(session).Should(Say("cf v3-set-health-check worker-app process --process worker")) 37 Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --endpoint /foo")) 38 Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --invocation-timeout 10")) 39 40 Eventually(session).Should(Say("OPTIONS:")) 41 Eventually(session).Should(Say(`--endpoint\s+Path on the app \(Default: /\)`)) 42 Eventually(session).Should(Say(`--invocation-timeout\s+Time \(in seconds\) that controls individual health check invocations`)) 43 Eventually(session).Should(Say(`--process\s+App process to update \(Default: web\)`)) 44 45 Eventually(session).Should(Exit(0)) 46 }) 47 }) 48 }) 49 50 Context("when the app name is not provided", func() { 51 It("tells the user that the app name is required, prints help text, and exits 1", func() { 52 session := helpers.CF("v3-set-health-check") 53 54 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `HEALTH_CHECK_TYPE` were not provided")) 55 Eventually(session).Should(Say("NAME:")) 56 Eventually(session).Should(Exit(1)) 57 }) 58 }) 59 60 Context("when the health check type is not provided", func() { 61 It("tells the user that health check type is required, prints help text, and exits 1", func() { 62 session := helpers.CF("v3-set-health-check", appName) 63 64 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `HEALTH_CHECK_TYPE` was not provided")) 65 Eventually(session).Should(Say("NAME:")) 66 Eventually(session).Should(Exit(1)) 67 }) 68 }) 69 70 It("displays the experimental warning", func() { 71 session := helpers.CF("v3-set-health-check", appName, "port") 72 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 73 Eventually(session).Should(Exit()) 74 }) 75 76 Context("when the environment is not setup correctly", func() { 77 Context("when no API endpoint is set", func() { 78 BeforeEach(func() { 79 helpers.UnsetAPI() 80 }) 81 82 It("fails with no API endpoint set message", func() { 83 session := helpers.CF("v3-set-health-check", appName, "port") 84 Eventually(session).Should(Say("FAILED")) 85 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 86 Eventually(session).Should(Exit(1)) 87 }) 88 }) 89 90 Context("when the v3 api does not exist", func() { 91 var server *Server 92 93 BeforeEach(func() { 94 server = helpers.StartAndTargetServerWithoutV3API() 95 }) 96 97 AfterEach(func() { 98 server.Close() 99 }) 100 101 It("fails with error message that the minimum version is not met", func() { 102 session := helpers.CF("v3-set-health-check", appName, "port") 103 Eventually(session).Should(Say("FAILED")) 104 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 105 Eventually(session).Should(Exit(1)) 106 }) 107 }) 108 109 Context("when the v3 api version is lower than the minimum version", func() { 110 var server *Server 111 112 BeforeEach(func() { 113 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 114 }) 115 116 AfterEach(func() { 117 server.Close() 118 }) 119 120 It("fails with error message that the minimum version is not met", func() { 121 session := helpers.CF("v3-set-health-check", appName, "port") 122 Eventually(session).Should(Say("FAILED")) 123 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 124 Eventually(session).Should(Exit(1)) 125 }) 126 }) 127 128 Context("when not logged in", func() { 129 BeforeEach(func() { 130 helpers.LogoutCF() 131 }) 132 133 It("fails with not logged in message", func() { 134 session := helpers.CF("v3-set-health-check", appName, "port") 135 Eventually(session).Should(Say("FAILED")) 136 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 137 Eventually(session).Should(Exit(1)) 138 }) 139 }) 140 141 Context("when there is no org set", func() { 142 BeforeEach(func() { 143 helpers.LogoutCF() 144 helpers.LoginCF() 145 }) 146 147 It("fails with no org targeted error message", func() { 148 session := helpers.CF("v3-set-health-check", appName, "port") 149 Eventually(session).Should(Say("FAILED")) 150 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 151 Eventually(session).Should(Exit(1)) 152 }) 153 }) 154 155 Context("when there is no space set", func() { 156 BeforeEach(func() { 157 helpers.LogoutCF() 158 helpers.LoginCF() 159 helpers.TargetOrg(ReadOnlyOrg) 160 }) 161 162 It("fails with no space targeted error message", func() { 163 session := helpers.CF("v3-set-health-check", appName, "port") 164 Eventually(session).Should(Say("FAILED")) 165 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 166 Eventually(session).Should(Exit(1)) 167 }) 168 }) 169 }) 170 171 Context("when the environment is set up correctly", func() { 172 var userName string 173 174 BeforeEach(func() { 175 helpers.SetupCF(orgName, spaceName) 176 userName, _ = helpers.GetCredentials() 177 }) 178 179 AfterEach(func() { 180 helpers.QuickDeleteOrg(orgName) 181 }) 182 183 Context("when the app exists", func() { 184 BeforeEach(func() { 185 helpers.WithProcfileApp(func(appDir string) { 186 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 187 }) 188 }) 189 190 Context("when the process type is set", func() { 191 It("displays the health check types for each process", func() { 192 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "console") 193 Eventually(session).Should(Say("Updating health check type for app %s process console in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 194 Eventually(session).Should(Say("TIP: An app restart is required for the change to take effect\\.")) 195 Eventually(session).Should(Exit(0)) 196 197 session = helpers.CF("v3-get-health-check", appName) 198 Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 199 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 200 Eventually(session).Should(Say(`web\s+port\s+1`)) 201 Eventually(session).Should(Say(`console\s+http\s+/healthcheck\s+1`)) 202 203 Eventually(session).Should(Exit(0)) 204 }) 205 }) 206 207 Context("when the invocation timeout is set", func() { 208 It("displays the health check types for each process", func() { 209 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--invocation-timeout", "2") 210 Eventually(session).Should(Say("Updating health check type for app %s process web in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 211 Eventually(session).Should(Say("TIP: An app restart is required for the change to take effect\\.")) 212 Eventually(session).Should(Exit(0)) 213 214 session = helpers.CF("v3-get-health-check", appName) 215 Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 216 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 217 Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+2`)) 218 219 Eventually(session).Should(Exit(0)) 220 }) 221 222 }) 223 224 Context("when process type and invocation timeout are not set", func() { 225 It("displays the health check types for each process", func() { 226 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck") 227 Eventually(session).Should(Say("Updating health check type for app %s process web in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 228 Eventually(session).Should(Say("TIP: An app restart is required for the change to take effect\\.")) 229 Eventually(session).Should(Exit(0)) 230 231 session = helpers.CF("v3-get-health-check", appName) 232 Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 233 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 234 Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+1`)) 235 Eventually(session).Should(Say(`console\s+process\s+1`)) 236 237 Eventually(session).Should(Exit(0)) 238 }) 239 }) 240 241 Context("when the process type does not exist", func() { 242 BeforeEach(func() { 243 helpers.WithProcfileApp(func(appDir string) { 244 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 245 }) 246 }) 247 248 It("returns a process not found error", func() { 249 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "nonexistent-type") 250 Eventually(session).Should(Say("Updating health check type for app %s process nonexistent-type in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 251 Eventually(session.Err).Should(Say("Process nonexistent-type not found")) 252 Eventually(session).Should(Say("FAILED")) 253 Eventually(session).Should(Exit(1)) 254 }) 255 }) 256 257 Context("when health check type is not 'http' and endpoint is set", func() { 258 It("returns an error", func() { 259 session := helpers.CF("v3-set-health-check", appName, "port", "--endpoint", "oh-no", "--process", "console") 260 Eventually(session.Out).Should(Say("Updating health check type for app %s process console in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 261 Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint.")) 262 Eventually(session.Out).Should(Say("FAILED")) 263 Eventually(session).Should(Exit(1)) 264 }) 265 }) 266 267 Context("when the invocation timeout is less than one", func() { 268 It("returns an error", func() { 269 session := helpers.CF("v3-set-health-check", appName, "port", "--invocation-timeout", "0", "--process", "console") 270 Eventually(session.Err).Should(Say("Value must be greater than or equal to 1.")) 271 Eventually(session).Should(Exit(1)) 272 }) 273 }) 274 }) 275 276 Context("when the app does not exist", func() { 277 It("displays app not found and exits 1", func() { 278 invalidAppName := "invalid-app-name" 279 session := helpers.CF("v3-set-health-check", invalidAppName, "port") 280 281 Eventually(session.Out).Should(Say("Updating health check type for app %s process web in org %s / space %s as %s\\.\\.\\.", invalidAppName, orgName, spaceName, userName)) 282 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 283 Eventually(session.Out).Should(Say("FAILED")) 284 285 Eventually(session).Should(Exit(1)) 286 }) 287 }) 288 }) 289 })