github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/get_health_check_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 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 ) 11 12 var _ = Describe("get-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 When("--help flag is set", func() { 27 It("appears in cf help -a", func() { 28 session := helpers.CF("help", "-a") 29 Eventually(session).Should(Exit(0)) 30 Expect(session).To(HaveCommandInCategoryWithDescription("get-health-check", "APPS", "Show the type of health check performed on an app")) 31 }) 32 33 It("Displays command usage to output", func() { 34 session := helpers.CF("get-health-check", "--help") 35 36 Eventually(session).Should(Say("NAME:")) 37 Eventually(session).Should(Say("get-health-check - Show the type of health check performed on an app")) 38 Eventually(session).Should(Say("USAGE:")) 39 Eventually(session).Should(Say("cf get-health-check APP_NAME")) 40 41 Eventually(session).Should(Exit(0)) 42 }) 43 }) 44 }) 45 46 When("the app name is not provided", func() { 47 It("tells the user that the app name is required, prints help text, and exits 1", func() { 48 session := helpers.CF("get-health-check") 49 50 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 51 Eventually(session).Should(Say("NAME:")) 52 Eventually(session).Should(Exit(1)) 53 }) 54 }) 55 56 When("the environment is not setup correctly", func() { 57 It("fails with the appropriate errors", func() { 58 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "get-health-check", appName) 59 }) 60 }) 61 62 When("the environment is set up correctly", func() { 63 var username string 64 65 BeforeEach(func() { 66 helpers.SetupCF(orgName, spaceName) 67 username, _ = helpers.GetCredentials() 68 }) 69 70 AfterEach(func() { 71 helpers.QuickDeleteOrg(orgName) 72 }) 73 74 When("the input is invalid", func() { 75 When("there are not enough arguments", func() { 76 It("outputs the usage and exits 1", func() { 77 session := helpers.CF("get-health-check") 78 79 Eventually(session.Err).Should(Say("Incorrect Usage:")) 80 Eventually(session).Should(Say("NAME:")) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 }) 85 86 When("the app exists", func() { 87 BeforeEach(func() { 88 helpers.WithProcfileApp(func(appDir string) { 89 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName, "--no-start")).Should(Exit(0)) 90 }) 91 }) 92 93 It("displays the health check types for each process", func() { 94 session := helpers.CF("get-health-check", appName) 95 96 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 97 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`)) 98 Eventually(session).Should(Say(`web\s+port\s+1\n`)) 99 100 Eventually(session).Should(Exit(0)) 101 }) 102 103 When("the health check type is http", func() { 104 BeforeEach(func() { 105 Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0)) 106 }) 107 108 It("shows the health check type is http with an endpoint of `/`", func() { 109 session := helpers.CF("get-health-check", appName) 110 111 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 112 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`)) 113 Eventually(session).Should(Say(`web\s+http\s+/\s+1\n`)) 114 115 Eventually(session).Should(Exit(0)) 116 }) 117 }) 118 119 When("the health check type is http with a custom endpoint", func() { 120 BeforeEach(func() { 121 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 122 }) 123 124 It("shows the health check type is http with the custom endpoint", func() { 125 session := helpers.CF("get-health-check", appName) 126 127 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 128 Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`)) 129 Eventually(session).Should(Say(`web\s+http\s+/some-endpoint\s+1\n`)) 130 131 Eventually(session).Should(Exit(0)) 132 }) 133 }) 134 135 When("the health check type is port", func() { 136 BeforeEach(func() { 137 Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0)) 138 }) 139 140 It("shows that the health check type is port", func() { 141 session := helpers.CF("get-health-check", appName) 142 143 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 144 Eventually(session).Should(Say(`web\s+port\s+\d+`)) 145 146 Eventually(session).Should(Exit(0)) 147 }) 148 }) 149 150 When("the health check type is process", func() { 151 BeforeEach(func() { 152 Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0)) 153 }) 154 155 It("shows that the health check type is process", func() { 156 session := helpers.CF("get-health-check", appName) 157 158 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 159 Eventually(session).Should(Say(`web\s+process\s+\d+`)) 160 161 Eventually(session).Should(Exit(0)) 162 }) 163 }) 164 165 When("the health check type changes from http to another type", func() { 166 BeforeEach(func() { 167 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 168 Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0)) 169 }) 170 171 It("does not show an endpoint", func() { 172 session := helpers.CF("get-health-check", appName) 173 174 Consistently(session).ShouldNot(Say("/some-endpoint")) 175 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 176 Eventually(session).Should(Say("\n\n")) 177 Eventually(session).Should(Say(`web\s+process\s+\d+`)) 178 179 Eventually(session).Should(Exit(0)) 180 }) 181 }) 182 }) 183 184 When("the app does not exist", func() { 185 It("displays app not found and exits 1", func() { 186 session := helpers.CF("get-health-check", appName) 187 188 Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username)) 189 Eventually(session.Err).Should(Say("App '%s' not found", appName)) 190 Eventually(session).Should(Say("FAILED")) 191 192 Eventually(session).Should(Exit(1)) 193 }) 194 }) 195 }) 196 })