github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/v7/isolated/unset_env_command_test.go (about) 1 package isolated 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("unset-env command", func() { 14 var ( 15 orgName string 16 spaceName string 17 appName string 18 envVarName 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 }) 27 28 Describe("help", func() { 29 When("--help flag is set", func() { 30 It("displays command usage to output", func() { 31 session := helpers.CF("unset-env", "--help") 32 33 Eventually(session).Should(Say("NAME:")) 34 Eventually(session).Should(Say("unset-env - Remove an env variable from an app")) 35 Eventually(session).Should(Say("USAGE:")) 36 Eventually(session).Should(Say("cf unset-env APP_NAME ENV_VAR_NAME")) 37 Eventually(session).Should(Say("ALIAS:")) 38 Eventually(session).Should(Say("ue")) 39 Eventually(session).Should(Say("SEE ALSO:")) 40 Eventually(session).Should(Say("env, set-env, v3-apps, v3-restart, v3-stage")) 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("unset-env") 49 50 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `ENV_VAR_NAME` were not provided")) 51 Eventually(session).Should(Say("NAME:")) 52 Eventually(session).Should(Exit(1)) 53 }) 54 }) 55 56 When("ENV_VAR_NAME is not provided", func() { 57 It("tells the user that ENV_VAR_NAME is required, prints help text, and exits 1", func() { 58 session := helpers.CF("unset-env", appName) 59 60 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ENV_VAR_NAME` was not provided")) 61 Eventually(session).Should(Say("NAME:")) 62 Eventually(session).Should(Exit(1)) 63 }) 64 }) 65 66 When("the environment is not setup correctly", func() { 67 It("fails with the appropriate errors", func() { 68 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "unset-env", appName, envVarName) 69 }) 70 }) 71 72 When("the environment is set up correctly", func() { 73 var userName string 74 75 BeforeEach(func() { 76 helpers.SetupCF(orgName, spaceName) 77 userName, _ = helpers.GetCredentials() 78 }) 79 80 When("the app does not exist", func() { 81 It("displays app not found and exits 1", func() { 82 invalidAppName := "invalid-app-name" 83 session := helpers.CF("unset-env", invalidAppName, envVarName) 84 85 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, invalidAppName, orgName, spaceName, userName)) 86 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 87 Eventually(session).Should(Say("FAILED")) 88 Eventually(session).Should(Exit(1)) 89 }) 90 }) 91 92 When("the app exists", func() { 93 BeforeEach(func() { 94 helpers.WithHelloWorldApp(func(appDir string) { 95 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0)) 96 }) 97 }) 98 99 When("the environment variable has not been previously set", func() { 100 It("returns a warning indicating variable was not set", func() { 101 session := helpers.CF("unset-env", appName, envVarName) 102 103 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, appName, orgName, spaceName, userName)) 104 Eventually(session).Should(Say("Env variable %s was not set.", envVarName)) 105 Eventually(session).Should(Say("OK")) 106 Eventually(session).Should(Exit(0)) 107 }) 108 }) 109 110 When("the environment variable has been previously set", func() { 111 BeforeEach(func() { 112 Eventually(helpers.CF("set-env", appName, envVarName, "some-value")).Should(Exit(0)) 113 }) 114 115 It("overrides the value of the existing environment variable", func() { 116 session := helpers.CF("unset-env", appName, envVarName) 117 118 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, appName, orgName, spaceName, userName)) 119 Eventually(session).Should(Say("OK")) 120 Eventually(session).Should(Say(`TIP: Use 'cf v3-stage %s' to ensure your env variable changes take effect\.`, appName)) 121 122 session = helpers.CF("curl", fmt.Sprintf("v3/apps/%s/environment_variables", helpers.AppGUID(appName))) 123 Eventually(session).ShouldNot(Say(`"%s"`, envVarName)) 124 Eventually(session).Should(Exit(0)) 125 }) 126 }) 127 }) 128 }) 129 })