github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/set_droplet_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("set-droplet command", func() { 16 var ( 17 orgName string 18 spaceName string 19 appName string 20 ) 21 22 BeforeEach(func() { 23 orgName = helpers.NewOrgName() 24 spaceName = helpers.NewSpaceName() 25 appName = helpers.PrefixedRandomName("app") 26 }) 27 28 Describe("help", func() { 29 When("--help flag is set", func() { 30 It("appears in cf help -a", func() { 31 session := helpers.CF("help", "-a") 32 Eventually(session).Should(Exit(0)) 33 Expect(session).To(HaveCommandInCategoryWithDescription("set-droplet", "APPS", "Set the droplet used to run an app")) 34 }) 35 36 It("Displays command usage to output", func() { 37 session := helpers.CF("set-droplet", "--help") 38 39 Eventually(session).Should(Say("NAME:")) 40 Eventually(session).Should(Say("set-droplet - Set the droplet used to run an app")) 41 Eventually(session).Should(Say("USAGE:")) 42 Eventually(session).Should(Say("cf set-droplet APP_NAME -d DROPLET_GUID")) 43 Eventually(session).Should(Say("OPTIONS:")) 44 Eventually(session).Should(Say(`--droplet-guid, -d\s+The guid of the droplet to use`)) 45 Eventually(session).Should(Say("SEE ALSO:")) 46 Eventually(session).Should(Say("app, create-package, droplets, packages, push, stage")) 47 48 Eventually(session).Should(Exit(0)) 49 }) 50 }) 51 }) 52 53 When("the app name is not provided", func() { 54 It("tells the user that the app name is required, prints help text, and exits 1", func() { 55 session := helpers.CF("set-droplet", "-d", "some-droplet-guid") 56 57 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 58 Eventually(session).Should(Say("NAME:")) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 When("the package GUID flag is missing", func() { 64 It("displays incorrect usage", func() { 65 session := helpers.CF("set-droplet", "some-app") 66 67 Eventually(session.Err).Should(Say("Incorrect Usage: the required flag `-d, --droplet-guid' was not specified")) 68 Eventually(session).Should(Say("NAME:")) 69 70 Eventually(session).Should(Exit(1)) 71 }) 72 }) 73 74 When("the environment is not setup correctly", func() { 75 It("fails with the appropriate errors", func() { 76 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "set-droplet", appName, "--droplet-guid", "some-droplet-guid") 77 }) 78 }) 79 80 When("the environment is set up correctly", func() { 81 BeforeEach(func() { 82 helpers.SetupCF(orgName, spaceName) 83 }) 84 85 AfterEach(func() { 86 helpers.QuickDeleteOrg(orgName) 87 }) 88 89 When("the app exists", func() { 90 var dropletGUID string 91 92 BeforeEach(func() { 93 var packageGUID string 94 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 95 96 helpers.WithHelloWorldApp(func(appDir string) { 97 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName) 98 Eventually(pkgSession).Should(Exit(0)) 99 regex := regexp.MustCompile(`Package with guid '(.+)' has been created\.`) 100 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 101 Expect(matches).To(HaveLen(2)) 102 103 packageGUID = matches[1] 104 }) 105 106 stageSession := helpers.CF("stage", appName, "--package-guid", packageGUID) 107 Eventually(stageSession).Should(Exit(0)) 108 109 regex := regexp.MustCompile(`droplet guid:\s+(.+)`) 110 matches := regex.FindStringSubmatch(string(stageSession.Out.Contents())) 111 Expect(matches).To(HaveLen(2)) 112 113 dropletGUID = matches[1] 114 }) 115 116 It("sets the droplet for the app", func() { 117 userName, _ := helpers.GetCredentials() 118 119 session := helpers.CF("set-droplet", appName, "-d", dropletGUID) 120 Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, dropletGUID, orgName, spaceName, userName)) 121 Eventually(session).Should(Say("OK")) 122 123 Eventually(session).Should(Exit(0)) 124 }) 125 126 When("the app does not exist", func() { 127 It("displays app not found and exits 1", func() { 128 invalidAppName := "invalid-app-name" 129 session := helpers.CF("set-droplet", invalidAppName, "-d", dropletGUID) 130 userName, _ := helpers.GetCredentials() 131 132 Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, invalidAppName, dropletGUID, orgName, spaceName, userName)) 133 Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName)) 134 Eventually(session).Should(Say("FAILED")) 135 136 Eventually(session).Should(Exit(1)) 137 }) 138 }) 139 140 When("the droplet does not exist", func() { 141 It("displays droplet not found and exits 1", func() { 142 invalidDropletGUID := "some-droplet-guid" 143 session := helpers.CF("set-droplet", appName, "-d", invalidDropletGUID) 144 userName, _ := helpers.GetCredentials() 145 146 Eventually(session).Should(Say(`Setting app %s to droplet %s in org %s / space %s as %s\.\.\.`, appName, invalidDropletGUID, orgName, spaceName, userName)) 147 Eventually(session.Err).Should(Say(`Unable to assign droplet: Unable to assign current droplet\. Ensure the droplet exists and belongs to this app\.`)) 148 Eventually(session).Should(Say("FAILED")) 149 Eventually(session).Should(Exit(1)) 150 }) 151 }) 152 }) 153 }) 154 })