github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/get_health_check_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 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 Describe("help", func() { 14 Context("when --help flag is set", func() { 15 It("Displays command usage to output", func() { 16 session := helpers.CF("get-health-check", "--help") 17 18 Eventually(session).Should(Say("NAME:")) 19 Eventually(session).Should(Say(" get-health-check - Show the type of health check performed on an app")) 20 Eventually(session).Should(Say("USAGE:")) 21 Eventually(session).Should(Say(" cf get-health-check APP_NAME")) 22 Eventually(session).Should(Exit(0)) 23 }) 24 }) 25 }) 26 27 Context("when the environment is not setup correctly", func() { 28 It("fails with the appropriate errors", func() { 29 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "get-health-check", "app-name") 30 }) 31 }) 32 33 Context("when the environment is set up correctly", func() { 34 var ( 35 orgName string 36 spaceName string 37 ) 38 39 BeforeEach(func() { 40 orgName = helpers.NewOrgName() 41 spaceName = helpers.NewSpaceName() 42 43 helpers.SetupCF(orgName, spaceName) 44 }) 45 46 AfterEach(func() { 47 helpers.QuickDeleteOrg(orgName) 48 }) 49 50 Context("when the input is invalid", func() { 51 Context("when there are not enough arguments", func() { 52 It("outputs the usage and exits 1", func() { 53 session := helpers.CF("get-health-check") 54 55 Eventually(session.Err).Should(Say("Incorrect Usage:")) 56 Eventually(session).Should(Say("NAME:")) 57 Eventually(session).Should(Exit(1)) 58 }) 59 }) 60 61 Context("when there too many arguments", func() { 62 It("ignores the extra arguments", func() { 63 appName := helpers.PrefixedRandomName("app") 64 session := helpers.CF("get-health-check", appName, "extra") 65 username, _ := helpers.GetCredentials() 66 67 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 68 Eventually(session.Err).Should(Say("App %s not found", appName)) 69 Eventually(session).Should(Say("FAILED")) 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 }) 74 75 Context("when the app does not exist", func() { 76 It("tells the user that the app is not found and exits 1", func() { 77 appName := helpers.PrefixedRandomName("app") 78 session := helpers.CF("get-health-check", appName) 79 username, _ := helpers.GetCredentials() 80 81 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 82 Eventually(session.Err).Should(Say("App %s not found", appName)) 83 Eventually(session).Should(Say("FAILED")) 84 Eventually(session).Should(Exit(1)) 85 }) 86 }) 87 88 Context("when the app exists", func() { 89 var ( 90 appName string 91 username string 92 ) 93 94 BeforeEach(func() { 95 appName = helpers.PrefixedRandomName("app") 96 helpers.WithHelloWorldApp(func(appDir string) { 97 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 98 }) 99 username, _ = helpers.GetCredentials() 100 }) 101 102 Context("when the health check type is http", func() { 103 BeforeEach(func() { 104 Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0)) 105 }) 106 107 It("shows an endpoint", func() { 108 session := helpers.CF("get-health-check", appName) 109 110 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 111 Eventually(session).Should(Say("\n\n")) 112 Eventually(session).Should(Say("health check type: http")) 113 Eventually(session).Should(Say("endpoint \\(for http type\\): /")) 114 Eventually(session).Should(Exit(0)) 115 }) 116 }) 117 118 Context("when the health check type is http with a custom endpoint", func() { 119 BeforeEach(func() { 120 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 121 }) 122 123 It("show the custom endpoint", func() { 124 session := helpers.CF("get-health-check", appName) 125 126 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 127 Eventually(session).Should(Say("\n\n")) 128 Eventually(session).Should(Say("health check type: http")) 129 Eventually(session).Should(Say("endpoint \\(for http type\\): /some-endpoint")) 130 Eventually(session).Should(Exit(0)) 131 }) 132 }) 133 134 Context("when the health check type is none", func() { 135 BeforeEach(func() { 136 Eventually(helpers.CF("set-health-check", appName, "none")).Should(Exit(0)) 137 }) 138 139 It("does not show an endpoint", func() { 140 session := helpers.CF("get-health-check", appName) 141 142 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 143 Eventually(session).Should(Say("\n\n")) 144 Eventually(session).Should(Say("health check type: none")) 145 Eventually(session).Should(Say("(?m)endpoint \\(for http type\\): $")) 146 Eventually(session).Should(Exit(0)) 147 }) 148 }) 149 150 Context("when the health check type is port", func() { 151 BeforeEach(func() { 152 Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0)) 153 }) 154 155 It("does not show an endpoint", 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("\n\n")) 160 Eventually(session).Should(Say("health check type: port")) 161 Eventually(session).Should(Say("(?m)endpoint \\(for http type\\): $")) 162 Eventually(session).Should(Exit(0)) 163 }) 164 }) 165 166 Context("when the health check type is process", func() { 167 BeforeEach(func() { 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 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 175 Eventually(session).Should(Say("\n\n")) 176 Eventually(session).Should(Say("health check type: process")) 177 Eventually(session).Should(Say("(?m)endpoint \\(for http type\\): $")) 178 Eventually(session).Should(Exit(0)) 179 }) 180 }) 181 182 Context("when the health check type changes from http to another type", func() { 183 BeforeEach(func() { 184 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 185 Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0)) 186 }) 187 188 It("does not show an endpoint", func() { 189 session := helpers.CF("get-health-check", appName) 190 191 Eventually(session).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username)) 192 Eventually(session).Should(Say("\n\n")) 193 Eventually(session).Should(Say("health check type: process")) 194 Eventually(session).Should(Say("(?m)endpoint \\(for http type\\): $")) 195 Eventually(session).Should(Exit(0)) 196 }) 197 }) 198 }) 199 }) 200 })