github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/v6/experimental/v3_set_health_check_command_test.go (about) 1 package experimental 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("v3-set-health-check command", func() { 14 var ( 15 orgName string 16 spaceName string 17 appName string 18 ) 19 20 BeforeEach(func() { 21 orgName = helpers.NewOrgName() 22 spaceName = helpers.NewSpaceName() 23 appName = helpers.PrefixedRandomName("app") 24 }) 25 26 Describe("help", func() { 27 When("--help flag is set", func() { 28 It("Displays command usage to output", func() { 29 session := helpers.CF("v3-set-health-check", "--help") 30 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("v3-set-health-check - Change type of health check performed on an app's process")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say(`cf v3-set-health-check APP_NAME \(process \| port \| http \[--endpoint PATH\]\) \[--process PROCESS\] \[--invocation-timeout INVOCATION_TIMEOUT\]`)) 35 36 Eventually(session).Should(Say("EXAMPLES:")) 37 Eventually(session).Should(Say("cf v3-set-health-check worker-app process --process worker")) 38 Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --endpoint /foo")) 39 Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --invocation-timeout 10")) 40 41 Eventually(session).Should(Say("OPTIONS:")) 42 Eventually(session).Should(Say(`--endpoint\s+Path on the app \(Default: /\)`)) 43 Eventually(session).Should(Say(`--invocation-timeout\s+Time \(in seconds\) that controls individual health check invocations`)) 44 Eventually(session).Should(Say(`--process\s+App process to update \(Default: web\)`)) 45 46 Eventually(session).Should(Exit(0)) 47 }) 48 }) 49 }) 50 51 When("the app name is not provided", func() { 52 It("tells the user that the app name is required, prints help text, and exits 1", func() { 53 session := helpers.CF("v3-set-health-check") 54 55 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `HEALTH_CHECK_TYPE` were not provided")) 56 Eventually(session).Should(Say("NAME:")) 57 Eventually(session).Should(Exit(1)) 58 }) 59 }) 60 61 When("the health check type is not provided", func() { 62 It("tells the user that health check type is required, prints help text, and exits 1", func() { 63 session := helpers.CF("v3-set-health-check", appName) 64 65 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `HEALTH_CHECK_TYPE` was not provided")) 66 Eventually(session).Should(Say("NAME:")) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 71 It("displays the experimental warning", func() { 72 session := helpers.CF("v3-set-health-check", appName, "port") 73 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 74 Eventually(session).Should(Exit()) 75 }) 76 77 When("the environment is not setup correctly", func() { 78 When("no API endpoint is set", func() { 79 BeforeEach(func() { 80 helpers.UnsetAPI() 81 }) 82 83 It("fails with no API endpoint set message", func() { 84 session := helpers.CF("v3-set-health-check", appName, "port") 85 Eventually(session).Should(Say("FAILED")) 86 Eventually(session.Err).Should(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`)) 87 Eventually(session).Should(Exit(1)) 88 }) 89 }) 90 91 When("the v3 api version is lower than the minimum version", func() { 92 var server *Server 93 94 BeforeEach(func() { 95 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 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-set-health-check", appName, "port") 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 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-set-health-check", appName, "port") 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 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-set-health-check", appName, "port") 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 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-set-health-check", appName, "port") 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 When("the environment is set up correctly", func() { 154 var userName string 155 156 BeforeEach(func() { 157 helpers.SetupCF(orgName, spaceName) 158 userName, _ = helpers.GetCredentials() 159 }) 160 161 AfterEach(func() { 162 helpers.QuickDeleteOrg(orgName) 163 }) 164 165 When("the app exists", func() { 166 BeforeEach(func() { 167 helpers.WithProcfileApp(func(appDir string) { 168 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 169 }) 170 }) 171 172 When("the process type is set", func() { 173 It("displays the health check types for each process", func() { 174 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "console") 175 Eventually(session).Should(Say(`Updating health check type for app %s process console in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 176 Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`)) 177 Eventually(session).Should(Exit(0)) 178 179 session = helpers.CF("v3-get-health-check", appName) 180 Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 181 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 182 Eventually(session).Should(Say(`web\s+port\s+1`)) 183 Eventually(session).Should(Say(`console\s+http\s+/healthcheck\s+1`)) 184 185 Eventually(session).Should(Exit(0)) 186 }) 187 }) 188 189 When("the invocation timeout is set", func() { 190 It("displays the health check types for each process", func() { 191 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--invocation-timeout", "2") 192 Eventually(session).Should(Say(`Updating health check type for app %s process web in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 193 Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`)) 194 Eventually(session).Should(Exit(0)) 195 196 session = helpers.CF("v3-get-health-check", appName) 197 Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 198 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 199 Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+2`)) 200 201 Eventually(session).Should(Exit(0)) 202 }) 203 204 }) 205 206 When("process type and invocation timeout are not set", func() { 207 It("displays the health check types for each process", func() { 208 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck") 209 Eventually(session).Should(Say(`Updating health check type for app %s process web in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 210 Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`)) 211 Eventually(session).Should(Exit(0)) 212 213 session = helpers.CF("v3-get-health-check", appName) 214 Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 215 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`)) 216 Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+1`)) 217 Eventually(session).Should(Say(`console\s+process\s+1`)) 218 219 Eventually(session).Should(Exit(0)) 220 }) 221 }) 222 223 When("the process type does not exist", func() { 224 BeforeEach(func() { 225 helpers.WithProcfileApp(func(appDir string) { 226 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 227 }) 228 }) 229 230 It("returns a process not found error", func() { 231 session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "nonexistent-type") 232 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)) 233 Eventually(session.Err).Should(Say("Process nonexistent-type not found")) 234 Eventually(session).Should(Say("FAILED")) 235 Eventually(session).Should(Exit(1)) 236 }) 237 }) 238 239 When("health check type is not 'http' and endpoint is set", func() { 240 It("returns an error", func() { 241 session := helpers.CF("v3-set-health-check", appName, "port", "--endpoint", "oh-no", "--process", "console") 242 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)) 243 Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint.")) 244 Eventually(session.Out).Should(Say("FAILED")) 245 Eventually(session).Should(Exit(1)) 246 }) 247 }) 248 249 When("the invocation timeout is less than one", func() { 250 It("returns an error", func() { 251 session := helpers.CF("v3-set-health-check", appName, "port", "--invocation-timeout", "0", "--process", "console") 252 Eventually(session.Err).Should(Say("Value must be greater than or equal to 1.")) 253 Eventually(session).Should(Exit(1)) 254 }) 255 }) 256 }) 257 258 When("the app does not exist", func() { 259 It("displays app not found and exits 1", func() { 260 invalidAppName := "invalid-app-name" 261 session := helpers.CF("v3-set-health-check", invalidAppName, "port") 262 263 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)) 264 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 265 Eventually(session.Out).Should(Say("FAILED")) 266 267 Eventually(session).Should(Exit(1)) 268 }) 269 }) 270 }) 271 })