github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/v6/experimental/v3_unset_env_command_test.go (about) 1 package experimental 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 . "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("v3-unset-env command", func() { 16 var ( 17 orgName string 18 spaceName string 19 appName string 20 envVarName string 21 ) 22 23 BeforeEach(func() { 24 orgName = helpers.NewOrgName() 25 spaceName = helpers.NewSpaceName() 26 appName = helpers.PrefixedRandomName("app") 27 envVarName = "SOME_ENV_VAR" 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-unset-env", "--help") 34 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("v3-unset-env - Remove an env variable from an app")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say("cf v3-unset-env APP_NAME ENV_VAR_NAME")) 39 Eventually(session).Should(Say("SEE ALSO:")) 40 Eventually(session).Should(Say("v3-apps, v3-env, v3-restart, v3-set-env, 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("v3-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("v3-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 It("displays the experimental warning", func() { 67 session := helpers.CF("v3-unset-env", appName, envVarName) 68 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 69 Eventually(session).Should(Exit()) 70 }) 71 72 When("the environment is not setup correctly", func() { 73 When("the v3 api version is lower than the minimum version", func() { 74 var server *Server 75 76 BeforeEach(func() { 77 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 78 }) 79 80 AfterEach(func() { 81 server.Close() 82 }) 83 84 It("fails with error message that the minimum version is not met", func() { 85 session := helpers.CF("v3-unset-env", appName, envVarName) 86 Eventually(session).Should(Say("FAILED")) 87 Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`)) 88 Eventually(session).Should(Exit(1)) 89 }) 90 }) 91 92 When("no API endpoint is set", func() { 93 BeforeEach(func() { 94 helpers.UnsetAPI() 95 }) 96 97 It("fails with no API endpoint set message", func() { 98 session := helpers.CF("v3-unset-env", appName, envVarName) 99 Eventually(session).Should(Say("FAILED")) 100 Eventually(session.Err).Should(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`)) 101 Eventually(session).Should(Exit(1)) 102 }) 103 }) 104 105 When("not logged in", func() { 106 BeforeEach(func() { 107 helpers.LogoutCF() 108 }) 109 110 It("fails with not logged in message", func() { 111 session := helpers.CF("v3-unset-env", appName, envVarName) 112 Eventually(session).Should(Say("FAILED")) 113 Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' to log in\.`)) 114 Eventually(session).Should(Exit(1)) 115 }) 116 }) 117 118 When("there is no org set", func() { 119 BeforeEach(func() { 120 helpers.LogoutCF() 121 helpers.LoginCF() 122 }) 123 124 It("fails with no org targeted error message", func() { 125 session := helpers.CF("v3-unset-env", appName, envVarName) 126 Eventually(session).Should(Say("FAILED")) 127 Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`)) 128 Eventually(session).Should(Exit(1)) 129 }) 130 }) 131 132 When("there is no space set", func() { 133 BeforeEach(func() { 134 helpers.LogoutCF() 135 helpers.LoginCF() 136 helpers.TargetOrg(ReadOnlyOrg) 137 }) 138 139 It("fails with no space targeted error message", func() { 140 session := helpers.CF("v3-unset-env", appName, envVarName) 141 Eventually(session).Should(Say("FAILED")) 142 Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`)) 143 Eventually(session).Should(Exit(1)) 144 }) 145 }) 146 }) 147 148 When("the environment is set up correctly", func() { 149 var userName string 150 151 BeforeEach(func() { 152 helpers.SetupCF(orgName, spaceName) 153 userName, _ = helpers.GetCredentials() 154 }) 155 156 When("the app does not exist", func() { 157 It("displays app not found and exits 1", func() { 158 invalidAppName := "invalid-app-name" 159 session := helpers.CF("v3-unset-env", invalidAppName, envVarName) 160 161 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, invalidAppName, orgName, spaceName, userName)) 162 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 163 Eventually(session).Should(Say("FAILED")) 164 Eventually(session).Should(Exit(1)) 165 }) 166 }) 167 168 When("the app exists", func() { 169 BeforeEach(func() { 170 helpers.WithHelloWorldApp(func(appDir string) { 171 Eventually(helpers.CF("v3-push", appName, "-p", appDir)).Should(Exit(0)) 172 }) 173 }) 174 175 When("the environment variable has not been previously set", func() { 176 It("returns a warning indicating variable was not set", func() { 177 session := helpers.CF("v3-unset-env", appName, envVarName) 178 179 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, appName, orgName, spaceName, userName)) 180 Eventually(session).Should(Say("Env variable %s was not set.", envVarName)) 181 Eventually(session).Should(Say("OK")) 182 Eventually(session).Should(Exit(0)) 183 }) 184 }) 185 186 When("the environment variable has been previously set", func() { 187 BeforeEach(func() { 188 Eventually(helpers.CF("v3-set-env", appName, envVarName, "some-value")).Should(Exit(0)) 189 }) 190 191 It("overrides the value of the existing environment variable", func() { 192 session := helpers.CF("v3-unset-env", appName, envVarName) 193 194 Eventually(session).Should(Say(`Removing env variable %s from app %s in org %s / space %s as %s\.\.\.`, envVarName, appName, orgName, spaceName, userName)) 195 Eventually(session).Should(Say("OK")) 196 Eventually(session).Should(Say(`TIP: Use 'cf v3-stage %s' to ensure your env variable changes take effect\.`, appName)) 197 198 session = helpers.CF("curl", fmt.Sprintf("v3/apps/%s/environment_variables", helpers.AppGUID(appName))) 199 Eventually(session).ShouldNot(Say(`"%s"`, envVarName)) 200 Eventually(session).Should(Exit(0)) 201 }) 202 }) 203 }) 204 }) 205 })