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