github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_unset_env_command_test.go (about) 1 package experimental 2 3 import ( 4 "fmt" 5 6 "github.com/liamawhite/cli-with-i18n/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 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("v3-unset-env command", func() { 15 var ( 16 orgName string 17 spaceName string 18 appName string 19 envVarName 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 }) 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-unset-env", "--help") 33 34 Eventually(session.Out).Should(Say("NAME:")) 35 Eventually(session.Out).Should(Say("v3-unset-env - Remove an env variable from an app")) 36 Eventually(session.Out).Should(Say("USAGE:")) 37 Eventually(session.Out).Should(Say("cf v3-unset-env APP_NAME ENV_VAR_NAME")) 38 Eventually(session.Out).Should(Say("SEE ALSO:")) 39 Eventually(session.Out).Should(Say("v3-apps, v3-env, v3-restart, v3-set-env, v3-stage")) 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-unset-env") 48 49 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `ENV_VAR_NAME` were not provided")) 50 Eventually(session.Out).Should(Say("NAME:")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 Context("when ENV_VAR_NAME is not provided", func() { 56 It("tells the user that ENV_VAR_NAME is required, prints help text, and exits 1", func() { 57 session := helpers.CF("v3-unset-env", appName) 58 59 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ENV_VAR_NAME` was not provided")) 60 Eventually(session.Out).Should(Say("NAME:")) 61 Eventually(session).Should(Exit(1)) 62 }) 63 }) 64 65 Context("when the environment is not setup correctly", func() { 66 Context("when the v3 api does not exist", func() { 67 var server *Server 68 69 BeforeEach(func() { 70 server = helpers.StartAndTargetServerWithoutV3API() 71 }) 72 73 AfterEach(func() { 74 server.Close() 75 }) 76 77 It("fails with error message that the minimum version is not met", func() { 78 session := helpers.CF("v3-unset-env", appName, envVarName) 79 Eventually(session).Should(Say("FAILED")) 80 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 81 Eventually(session).Should(Exit(1)) 82 }) 83 }) 84 85 Context("when the v3 api version is lower than the minimum version", func() { 86 var server *Server 87 88 BeforeEach(func() { 89 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 90 }) 91 92 AfterEach(func() { 93 server.Close() 94 }) 95 96 It("fails with error message that the minimum version is not met", func() { 97 session := helpers.CF("v3-unset-env", appName, envVarName) 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 Context("when no API endpoint is set", func() { 105 BeforeEach(func() { 106 helpers.UnsetAPI() 107 }) 108 109 It("fails with no API endpoint set message", func() { 110 session := helpers.CF("v3-unset-env", appName, envVarName) 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 113 Eventually(session).Should(Exit(1)) 114 }) 115 }) 116 117 Context("when not logged in", func() { 118 BeforeEach(func() { 119 helpers.LogoutCF() 120 }) 121 122 It("fails with not logged in message", func() { 123 session := helpers.CF("v3-unset-env", appName, envVarName) 124 Eventually(session).Should(Say("FAILED")) 125 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 126 Eventually(session).Should(Exit(1)) 127 }) 128 }) 129 130 Context("when there is no org set", func() { 131 BeforeEach(func() { 132 helpers.LogoutCF() 133 helpers.LoginCF() 134 }) 135 136 It("fails with no org targeted error message", func() { 137 session := helpers.CF("v3-unset-env", appName, envVarName) 138 Eventually(session.Out).Should(Say("FAILED")) 139 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 140 Eventually(session).Should(Exit(1)) 141 }) 142 }) 143 144 Context("when there is no space set", func() { 145 BeforeEach(func() { 146 helpers.LogoutCF() 147 helpers.LoginCF() 148 helpers.TargetOrg(ReadOnlyOrg) 149 }) 150 151 It("fails with no space targeted error message", func() { 152 session := helpers.CF("v3-unset-env", appName, envVarName) 153 Eventually(session.Out).Should(Say("FAILED")) 154 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 155 Eventually(session).Should(Exit(1)) 156 }) 157 }) 158 }) 159 160 Context("when the environment is set up correctly", func() { 161 var userName string 162 163 BeforeEach(func() { 164 setupCF(orgName, spaceName) 165 userName, _ = helpers.GetCredentials() 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-unset-env", invalidAppName, envVarName) 172 173 Eventually(session.Out).Should(Say("Removing env variable %s from app %s in org %s / space %s as %s\\.\\.\\.", envVarName, invalidAppName, orgName, spaceName, userName)) 174 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 175 Eventually(session.Out).Should(Say("FAILED")) 176 Eventually(session).Should(Exit(1)) 177 }) 178 }) 179 180 Context("when the app exists", func() { 181 BeforeEach(func() { 182 helpers.WithHelloWorldApp(func(appDir string) { 183 Eventually(helpers.CF("v3-push", appName, "-p", appDir)).Should(Exit(0)) 184 }) 185 }) 186 187 Context("when the environment variable has not been previously set", func() { 188 It("returns a warning indicating variable was not set", func() { 189 session := helpers.CF("v3-unset-env", appName, envVarName) 190 191 Eventually(session.Out).Should(Say("Removing env variable %s from app %s in org %s / space %s as %s\\.\\.\\.", envVarName, appName, orgName, spaceName, userName)) 192 Eventually(session.Out).Should(Say("Env variable %s was not set.", envVarName)) 193 Eventually(session.Out).Should(Say("OK")) 194 Eventually(session).Should(Exit(0)) 195 }) 196 }) 197 198 Context("when the environment variable has been previously set", func() { 199 BeforeEach(func() { 200 Eventually(helpers.CF("v3-set-env", appName, envVarName, "some-value")).Should(Exit(0)) 201 }) 202 203 It("overrides the value of the existing environment variable", func() { 204 session := helpers.CF("v3-unset-env", appName, envVarName) 205 206 Eventually(session.Out).Should(Say("Removing env variable %s from app %s in org %s / space %s as %s\\.\\.\\.", envVarName, appName, orgName, spaceName, userName)) 207 Eventually(session.Out).Should(Say("OK")) 208 Eventually(session.Out).Should(Say("TIP: Use 'cf v3-stage %s' to ensure your env variable changes take effect\\.", appName)) 209 210 session = helpers.CF("curl", fmt.Sprintf("v3/apps/%s/environment_variables", helpers.AppGUID(appName))) 211 Eventually(session.Out).ShouldNot(Say(`"%s"`, envVarName)) 212 Eventually(session).Should(Exit(0)) 213 }) 214 }) 215 }) 216 }) 217 })