github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/global/env_command_test.go (about) 1 package global 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("env command", func() { 14 var ( 15 orgName string 16 spaceName string 17 appName string 18 ) 19 20 BeforeEach(func() { 21 orgName = helpers.NewOrgName() 22 spaceName = helpers.NewSpaceName() 23 appName = helpers.PrefixedRandomName("app") 24 }) 25 26 Describe("help", func() { 27 When("--help flag is set", func() { 28 It("displays command usage to output", func() { 29 session := helpers.CF("env", "--help") 30 31 Eventually(session).Should(Say("NAME:")) 32 Eventually(session).Should(Say("env - Show all env variables for an app")) 33 Eventually(session).Should(Say("USAGE:")) 34 Eventually(session).Should(Say("cf env APP_NAME")) 35 Eventually(session).Should(Say("SEE ALSO:")) 36 Eventually(session).Should(Say("app, apps, running-environment-variable-group, set-env, staging-environment-variable-group, unset-env")) 37 Eventually(session).Should(Exit(0)) 38 }) 39 }) 40 }) 41 42 When("the app name is not provided", func() { 43 It("tells the user that the app name is required, prints help text, and exits 1", func() { 44 session := helpers.CF("env") 45 46 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 47 Eventually(session).Should(Say("NAME:")) 48 Eventually(session).Should(Exit(1)) 49 }) 50 }) 51 52 When("the environment is not setup correctly", func() { 53 It("fails with the appropriate errors", func() { 54 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "env", appName) 55 }) 56 }) 57 58 When("the environment is set up correctly", func() { 59 var userName string 60 61 BeforeEach(func() { 62 helpers.SetupCF(orgName, spaceName) 63 userName, _ = helpers.GetCredentials() 64 }) 65 66 AfterEach(func() { 67 helpers.QuickDeleteOrg(orgName) 68 }) 69 70 When("the app does not exist", func() { 71 It("displays app not found and exits 1", func() { 72 invalidAppName := "invalid-app-name" 73 session := helpers.CF("env", invalidAppName) 74 75 Eventually(session).Should(Say(`Getting env variables for app %s in org %s / space %s as %s\.\.\.`, invalidAppName, orgName, spaceName, userName)) 76 Eventually(session).Should(Say("OK")) 77 78 Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName)) 79 Eventually(session).Should(Say("FAILED")) 80 Eventually(session).Should(Exit(1)) 81 }) 82 }) 83 84 When("the app exists", func() { 85 var ( 86 userProvidedServiceName string 87 ) 88 BeforeEach(func() { 89 userProvidedServiceName = helpers.PrefixedRandomName("service") 90 helpers.WithHelloWorldApp(func(appDir string) { 91 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0)) 92 }) 93 94 Eventually(helpers.CF("set-env", appName, "user-provided-env-name", "user-provided-env-value")).Should(Exit(0)) 95 Eventually(helpers.CF("set-env", appName, "an-out-of-order-name", "some-env-value")).Should(Exit(0)) 96 Eventually(helpers.CF("set-env", appName, "Capital-env-var", "some-other-env-value")).Should(Exit(0)) 97 Eventually(helpers.CF("create-user-provided-service", userProvidedServiceName)).Should(Exit(0)) 98 Eventually(helpers.CF("bind-service", appName, userProvidedServiceName)).Should(Exit(0)) 99 Eventually(helpers.CF("set-running-environment-variable-group", `{"running-env-name": "running-env-value", "Xstring": "X"}`)).Should(Exit(0)) 100 Eventually(helpers.CF("set-staging-environment-variable-group", `{"staging-env-name": "staging-env-value", "Ystring": "Y"}`)).Should(Exit(0)) 101 }) 102 103 AfterEach(func() { 104 Eventually(helpers.CF("unbind-service", appName, userProvidedServiceName)).Should(Exit(0)) 105 Eventually(helpers.CF("delete-service", userProvidedServiceName)).Should(Exit(0)) 106 Eventually(helpers.CF("set-running-environment-variable-group", `{}`)).Should(Exit(0)) 107 Eventually(helpers.CF("set-staging-environment-variable-group", `{}`)).Should(Exit(0)) 108 }) 109 110 It("displays the environment variables", func() { 111 By("displaying env variables when they are set") 112 session := helpers.CF("env", appName) 113 114 Eventually(session).Should(Say(fmt.Sprintf(`Getting env variables for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))) 115 Eventually(session).Should(Say("OK")) 116 117 Eventually(session).Should(Say("System-Provided:")) 118 Eventually(session).Should(Say(`VCAP_SERVICES: {\s*\n`)) 119 Eventually(session).Should(Say("VCAP_APPLICATION")) 120 121 Eventually(session).Should(Say("User-Provided:")) 122 Eventually(session).Should(Say(`Capital-env-var:\s+some-other-env-value`)) 123 Eventually(session).Should(Say(`an-out-of-order-name:\s+some-env-value`)) 124 Eventually(session).Should(Say(`user-provided-env-name:\s+user-provided-env-value`)) 125 126 Eventually(session).Should(Say("Running Environment Variable Groups:")) 127 Eventually(session).Should(Say(`Xstring:\s+X`)) 128 Eventually(session).Should(Say(`running-env-name:\s+running-env-value`)) 129 130 Eventually(session).Should(Say("Staging Environment Variable Groups:")) 131 Eventually(session).Should(Say(`Ystring:\s+Y`)) 132 Eventually(session).Should(Say(`staging-env-name:\s+staging-env-value`)) 133 134 Eventually(session).Should(Exit(0)) 135 136 By("displaying help messages when they are not set") 137 Eventually(helpers.CF("unset-env", appName, "user-provided-env-name")).Should(Exit(0)) 138 Eventually(helpers.CF("unset-env", appName, "an-out-of-order-name")).Should(Exit(0)) 139 Eventually(helpers.CF("unset-env", appName, "Capital-env-var")).Should(Exit(0)) 140 Eventually(helpers.CF("unbind-service", appName, userProvidedServiceName)).Should(Exit(0)) 141 Eventually(helpers.CF("set-running-environment-variable-group", `{}`)).Should(Exit(0)) 142 Eventually(helpers.CF("set-staging-environment-variable-group", `{}`)).Should(Exit(0)) 143 144 session = helpers.CF("env", appName) 145 Eventually(session).Should(Say(`Getting env variables for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 146 Eventually(session).Should(Say("OK")) 147 148 Eventually(session).Should(Say("System-Provided:")) 149 Eventually(session).Should(Say("VCAP_SERVICES: {}")) 150 Eventually(session).Should(Say("VCAP_APPLICATION")) 151 152 Eventually(session).Should(Say("No user-provided env variables have been set")) 153 154 Eventually(session).Should(Say("No running env variables have been set")) 155 156 Eventually(session).Should(Say("No staging env variables have been set")) 157 Eventually(session).Should(Exit(0)) 158 }) 159 }) 160 }) 161 })