github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_set_droplet_command_test.go (about) 1 package experimental 2 3 import ( 4 "regexp" 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-set-droplet command", func() { 15 var ( 16 orgName string 17 spaceName string 18 appName string 19 ) 20 21 BeforeEach(func() { 22 orgName = helpers.NewOrgName() 23 spaceName = helpers.NewSpaceName() 24 appName = helpers.PrefixedRandomName("app") 25 }) 26 27 Describe("help", func() { 28 Context("when --help flag is set", func() { 29 It("Displays command usage to output", func() { 30 session := helpers.CF("v3-set-droplet", "--help") 31 32 Eventually(session.Out).Should(Say("NAME:")) 33 Eventually(session.Out).Should(Say("v3-set-droplet - Set the droplet used to run an app")) 34 Eventually(session.Out).Should(Say("USAGE:")) 35 Eventually(session.Out).Should(Say("cf v3-set-droplet APP_NAME -d DROPLET_GUID")) 36 Eventually(session.Out).Should(Say("OPTIONS:")) 37 Eventually(session.Out).Should(Say("--droplet-guid, -d\\s+The guid of the droplet to use")) 38 39 Eventually(session).Should(Exit(0)) 40 }) 41 }) 42 }) 43 44 Context("when the app name is not provided", func() { 45 It("tells the user that the app name is required, prints help text, and exits 1", func() { 46 session := helpers.CF("v3-set-droplet", "-d", "some-droplet-guid") 47 48 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 49 Eventually(session.Out).Should(Say("NAME:")) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 54 Context("when the package GUID flag is missing", func() { 55 It("displays incorrect usage", func() { 56 session := helpers.CF("v3-set-droplet", "some-app") 57 58 Eventually(session.Err).Should(Say("Incorrect Usage: the required flag `-d, --droplet-guid' was not specified")) 59 Eventually(session.Out).Should(Say("NAME:")) 60 61 Eventually(session).Should(Exit(1)) 62 }) 63 }) 64 65 Context("when the environment is not setup correctly", func() { 66 Context("when no API endpoint is set", func() { 67 BeforeEach(func() { 68 helpers.UnsetAPI() 69 }) 70 71 It("fails with no API endpoint set message", func() { 72 session := helpers.CF("v3-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 73 Eventually(session).Should(Say("FAILED")) 74 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 75 Eventually(session).Should(Exit(1)) 76 }) 77 }) 78 79 Context("when the v3 api does not exist", func() { 80 var server *Server 81 82 BeforeEach(func() { 83 server = helpers.StartAndTargetServerWithoutV3API() 84 }) 85 86 AfterEach(func() { 87 server.Close() 88 }) 89 90 It("fails with error message that the minimum version is not met", func() { 91 session := helpers.CF("v3-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 92 Eventually(session).Should(Say("FAILED")) 93 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 94 Eventually(session).Should(Exit(1)) 95 }) 96 }) 97 98 Context("when the v3 api version is lower than the minimum version", func() { 99 var server *Server 100 101 BeforeEach(func() { 102 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 103 }) 104 105 AfterEach(func() { 106 server.Close() 107 }) 108 109 It("fails with error message that the minimum version is not met", func() { 110 session := helpers.CF("v3-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 111 Eventually(session).Should(Say("FAILED")) 112 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 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-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 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-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 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-set-droplet", appName, "--droplet-guid", "some-droplet-guid") 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 BeforeEach(func() { 162 setupCF(orgName, spaceName) 163 }) 164 165 AfterEach(func() { 166 helpers.QuickDeleteOrg(orgName) 167 }) 168 169 Context("when the app exists", func() { 170 var dropletGUID string 171 172 BeforeEach(func() { 173 var packageGUID string 174 Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0)) 175 176 helpers.WithHelloWorldApp(func(appDir string) { 177 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName) 178 Eventually(pkgSession).Should(Exit(0)) 179 regex, err := regexp.Compile(`package guid: (.+)`) 180 Expect(err).ToNot(HaveOccurred()) 181 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 182 Expect(matches).To(HaveLen(2)) 183 184 packageGUID = matches[1] 185 }) 186 187 stageSession := helpers.CF("v3-stage", appName, "--package-guid", packageGUID) 188 Eventually(stageSession).Should(Exit(0)) 189 190 regex, err := regexp.Compile(`droplet guid:\s+(.+)`) 191 Expect(err).ToNot(HaveOccurred()) 192 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 193 Expect(matches).To(HaveLen(2)) 194 195 dropletGUID = matches[1] 196 }) 197 198 It("sets the droplet for the app", func() { 199 userName, _ := helpers.GetCredentials() 200 201 session := helpers.CF("v3-set-droplet", appName, "-d", dropletGUID) 202 Eventually(session.Out).Should(Say("Setting app %s to droplet %s in org %s / space %s as %s\\.\\.\\.", appName, dropletGUID, orgName, spaceName, userName)) 203 Eventually(session.Out).Should(Say("OK")) 204 205 Eventually(session).Should(Exit(0)) 206 }) 207 208 Context("when the app does not exist", func() { 209 It("displays app not found and exits 1", func() { 210 invalidAppName := "invalid-app-name" 211 session := helpers.CF("v3-set-droplet", invalidAppName, "-d", dropletGUID) 212 userName, _ := helpers.GetCredentials() 213 214 Eventually(session.Out).Should(Say("Setting app %s to droplet %s in org %s / space %s as %s\\.\\.\\.", invalidAppName, dropletGUID, orgName, spaceName, userName)) 215 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 216 Eventually(session.Out).Should(Say("FAILED")) 217 218 Eventually(session).Should(Exit(1)) 219 }) 220 }) 221 222 Context("when the droplet does not exist", func() { 223 It("displays droplet not found and exits 1", func() { 224 invalidDropletGUID := "some-droplet-guid" 225 session := helpers.CF("v3-set-droplet", appName, "-d", invalidDropletGUID) 226 userName, _ := helpers.GetCredentials() 227 228 Eventually(session.Out).Should(Say("Setting app %s to droplet %s in org %s / space %s as %s\\.\\.\\.", appName, invalidDropletGUID, orgName, spaceName, userName)) 229 Eventually(session.Err).Should(Say("Unable to assign droplet: Unable to assign current droplet\\. Ensure the droplet exists and belongs to this app\\.")) 230 Eventually(session.Out).Should(Say("FAILED")) 231 Eventually(session).Should(Exit(1)) 232 }) 233 }) 234 }) 235 }) 236 })