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