github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_env_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-env command", func() { 13 var ( 14 orgName string 15 spaceName string 16 appName string 17 envVarName string 18 envVarValue string 19 ) 20 21 BeforeEach(func() { 22 orgName = helpers.NewOrgName() 23 spaceName = helpers.NewSpaceName() 24 appName = helpers.PrefixedRandomName("app") 25 envVarName = "SOME_ENV_VAR" 26 envVarValue = "SOME_ENV_VAR_VALUE" 27 }) 28 29 Describe("help", func() { 30 Context("when --help flag is set", func() { 31 It("displays command usage to output", func() { 32 session := helpers.CF("v3-env", "--help") 33 34 Eventually(session).Should(Say("NAME:")) 35 Eventually(session).Should(Say("v3-env - Show all env variables for an app")) 36 Eventually(session).Should(Say("USAGE:")) 37 Eventually(session).Should(Say("cf v3-env APP_NAME")) 38 Eventually(session).Should(Say("SEE ALSO:")) 39 Eventually(session).Should(Say("running-environment-variable-group, staging-environment-variable-group, v3-app, v3-apps, v3-set-env, v3-unset-env")) 40 Eventually(session).Should(Exit(0)) 41 }) 42 }) 43 }) 44 45 Context("when the app name is not provided", func() { 46 It("tells the user that the app name is required, prints help text, and exits 1", func() { 47 session := helpers.CF("v3-env") 48 49 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 50 Eventually(session).Should(Say("NAME:")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 It("displays the experimental warning", func() { 56 session := helpers.CF("v3-env", appName) 57 Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 58 Eventually(session).Should(Exit()) 59 }) 60 61 Context("when the environment is not setup correctly", func() { 62 Context("when the v3 api does not exist", func() { 63 var server *Server 64 65 BeforeEach(func() { 66 server = helpers.StartAndTargetServerWithoutV3API() 67 }) 68 69 AfterEach(func() { 70 server.Close() 71 }) 72 73 It("fails with error message that the minimum version is not met", func() { 74 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 75 Eventually(session).Should(Say("FAILED")) 76 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 77 Eventually(session).Should(Exit(1)) 78 }) 79 }) 80 81 Context("when the v3 api version is lower than the minimum version", func() { 82 var server *Server 83 84 BeforeEach(func() { 85 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 86 }) 87 88 AfterEach(func() { 89 server.Close() 90 }) 91 92 It("fails with error message that the minimum version is not met", func() { 93 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 94 Eventually(session).Should(Say("FAILED")) 95 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 96 Eventually(session).Should(Exit(1)) 97 }) 98 }) 99 100 Context("when no API endpoint is set", func() { 101 BeforeEach(func() { 102 helpers.UnsetAPI() 103 }) 104 105 It("fails with no API endpoint set message", func() { 106 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 107 Eventually(session).Should(Say("FAILED")) 108 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 109 Eventually(session).Should(Exit(1)) 110 }) 111 }) 112 113 Context("when not logged in", func() { 114 BeforeEach(func() { 115 helpers.LogoutCF() 116 }) 117 118 It("fails with not logged in message", func() { 119 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 120 Eventually(session).Should(Say("FAILED")) 121 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 126 Context("when there is no org set", func() { 127 BeforeEach(func() { 128 helpers.LogoutCF() 129 helpers.LoginCF() 130 }) 131 132 It("fails with no org targeted error message", func() { 133 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 134 Eventually(session).Should(Say("FAILED")) 135 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 136 Eventually(session).Should(Exit(1)) 137 }) 138 }) 139 140 Context("when there is no space set", func() { 141 BeforeEach(func() { 142 helpers.LogoutCF() 143 helpers.LoginCF() 144 helpers.TargetOrg(ReadOnlyOrg) 145 }) 146 147 It("fails with no space targeted error message", func() { 148 session := helpers.CF("v3-env", appName, envVarName, envVarValue) 149 Eventually(session).Should(Say("FAILED")) 150 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 151 Eventually(session).Should(Exit(1)) 152 }) 153 }) 154 }) 155 156 Context("when the environment is set up correctly", func() { 157 var userName string 158 159 BeforeEach(func() { 160 setupCF(orgName, spaceName) 161 userName, _ = helpers.GetCredentials() 162 }) 163 164 AfterEach(func() { 165 helpers.QuickDeleteOrg(orgName) 166 }) 167 168 Context("when the app does not exist", func() { 169 It("displays app not found and exits 1", func() { 170 invalidAppName := "invalid-app-name" 171 session := helpers.CF("v3-env", invalidAppName) 172 173 Eventually(session).Should(Say("Getting env variables for app %s in org %s / space %s as %s\\.\\.\\.", invalidAppName, orgName, spaceName, userName)) 174 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 175 Eventually(session).Should(Say("FAILED")) 176 Eventually(session).Should(Exit(1)) 177 }) 178 }) 179 180 Context("when the app exists", func() { 181 var ( 182 userProvidedServiceName string 183 ) 184 BeforeEach(func() { 185 userProvidedServiceName = helpers.PrefixedRandomName("service") 186 helpers.WithHelloWorldApp(func(appDir string) { 187 Eventually(helpers.CF("v3-push", appName, "-p", appDir)).Should(Exit(0)) 188 }) 189 190 Eventually(helpers.CF("v3-set-env", appName, "user-provided-env-name", "user-provided-env-value")).Should(Exit(0)) 191 Eventually(helpers.CF("create-user-provided-service", userProvidedServiceName)).Should(Exit(0)) 192 Eventually(helpers.CF("bind-service", appName, userProvidedServiceName)).Should(Exit(0)) 193 Eventually(helpers.CF("set-running-environment-variable-group", `{"running-env-name": "running-env-value"}`)).Should(Exit(0)) 194 Eventually(helpers.CF("set-staging-environment-variable-group", `{"staging-env-name": "staging-env-value"}`)).Should(Exit(0)) 195 }) 196 197 AfterEach(func() { 198 Eventually(helpers.CF("unbind-service", appName, userProvidedServiceName)).Should(Exit(0)) 199 Eventually(helpers.CF("delete-service", userProvidedServiceName)).Should(Exit(0)) 200 Eventually(helpers.CF("set-running-environment-variable-group", `{}`)).Should(Exit(0)) 201 Eventually(helpers.CF("set-staging-environment-variable-group", `{}`)).Should(Exit(0)) 202 }) 203 204 It("displays the environment variables", func() { 205 By("displaying env variables when they are set") 206 session := helpers.CF("v3-env", appName) 207 Eventually(session).Should(Say("Getting env variables for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 208 Eventually(session).Should(Say("System-Provided:")) 209 Eventually(session).Should(Say("VCAP_SERVICES")) 210 Eventually(session).Should(Say("VCAP_APPLICATION")) 211 212 Eventually(session).Should(Say("User-Provided:")) 213 Eventually(session).Should(Say(`user-provided-env-name: "user-provided-env-value"`)) 214 215 Eventually(session).Should(Say("Running Environment Variable Groups:")) 216 Eventually(session).Should(Say(`running-env-name: "running-env-value"`)) 217 218 Eventually(session).Should(Say("Staging Environment Variable Groups:")) 219 Eventually(session).Should(Say(`staging-env-name: "staging-env-value"`)) 220 Eventually(session).Should(Exit(0)) 221 222 By("displaying help messages when they are not set") 223 Eventually(helpers.CF("v3-unset-env", appName, "user-provided-env-name")).Should(Exit(0)) 224 Eventually(helpers.CF("unbind-service", appName, userProvidedServiceName)).Should(Exit(0)) 225 Eventually(helpers.CF("set-running-environment-variable-group", `{}`)).Should(Exit(0)) 226 Eventually(helpers.CF("set-staging-environment-variable-group", `{}`)).Should(Exit(0)) 227 228 session = helpers.CF("v3-env", appName) 229 Eventually(session).Should(Say("Getting env variables for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 230 Eventually(session).Should(Say("System-Provided:")) 231 Eventually(session).ShouldNot(Say("VCAP_SERVICES")) 232 Eventually(session).Should(Say("VCAP_APPLICATION")) 233 234 Eventually(session).Should(Say("No user-provided env variables have been set")) 235 236 Eventually(session).Should(Say("No running env variables have been set")) 237 238 Eventually(session).Should(Say("No staging env variables have been set")) 239 Eventually(session).Should(Exit(0)) 240 }) 241 }) 242 }) 243 })