github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/stage_package_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 . "github.com/LukasHeimann/cloudfoundrycli/v8/cf/util/testhelpers/matchers" 7 8 "github.com/LukasHeimann/cloudfoundrycli/v8/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("stage-package 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("stage-package", "APPS", "Stage a package into a droplet")) 34 }) 35 36 It("Displays command usage to output", func() { 37 session := helpers.CF("stage-package", "--help") 38 39 Eventually(session).Should(Say("NAME:")) 40 Eventually(session).Should(Say("stage-package - Stage a package into a droplet")) 41 Eventually(session).Should(Say("USAGE:")) 42 Eventually(session).Should(Say(`cf stage-package APP_NAME \[--package-guid PACKAGE_GUID\]`)) 43 Eventually(session).Should(Say("ALIAS:")) 44 Eventually(session).Should(Say("stage")) 45 Eventually(session).Should(Say("OPTIONS:")) 46 Eventually(session).Should(Say(`--package-guid\s+The guid of the package to stage \(default: latest ready package\)`)) 47 Eventually(session).Should(Say("ENVIRONMENT:")) 48 Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`)) 49 Eventually(session).Should(Say("SEE ALSO:")) 50 Eventually(session).Should(Say("app, create-package, droplets, packages, push, set-droplet")) 51 52 Eventually(session).Should(Exit(0)) 53 }) 54 }) 55 }) 56 57 When("the app name is not provided", func() { 58 It("tells the user that the app name is required, prints help text, and exits 1", func() { 59 session := helpers.CF("stage-package", "--package-guid", "some-package-guid") 60 61 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 62 Eventually(session).Should(Say("NAME:")) 63 Eventually(session).Should(Exit(1)) 64 }) 65 }) 66 67 When("the environment is not setup correctly", func() { 68 It("fails with the appropriate errors", func() { 69 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "stage-package", appName, "--package-guid", "some-package-guid") 70 }) 71 }) 72 73 When("the environment is set up correctly", func() { 74 BeforeEach(func() { 75 helpers.SetupCF(orgName, spaceName) 76 }) 77 78 AfterEach(func() { 79 helpers.QuickDeleteOrg(orgName) 80 }) 81 82 When("the package GUID flag is provided", func() { 83 When("the app exists", func() { 84 var packageGUID string 85 86 BeforeEach(func() { 87 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 88 89 helpers.WithHelloWorldApp(func(appDir string) { 90 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName) 91 Eventually(pkgSession).Should(Exit(0)) 92 regex := regexp.MustCompile(`Package with guid '(.+)' has been created.`) 93 matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents())) 94 Expect(matches).To(HaveLen(2)) 95 96 packageGUID = matches[1] 97 }) 98 }) 99 100 It("stages the package", func() { 101 session := helpers.CF("stage-package", appName, "--package-guid", packageGUID) 102 userName, _ := helpers.GetCredentials() 103 104 Eventually(session).Should(Say(`Staging package for %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 105 Eventually(session).Should(Say(`Downloading staticfile_buildpack\.\.\.`), "Error streaming logs") 106 Eventually(session).Should(Say(`Uploading droplet\.\.\.`), "Error streaming logs") 107 Eventually(session).Should(Say("Package staged")) 108 Eventually(session).Should(Say(`droplet guid:\s+%s`, helpers.GUIDRegex)) 109 Eventually(session).Should(Say(`state:\s+staged`)) 110 Eventually(session).Should(Say(`created:\s+%s`, helpers.UserFriendlyDateRegex)) 111 112 Eventually(session).Should(Exit(0)) 113 }) 114 115 When("the package belongs to a different app", func() { 116 var otherAppName string 117 118 BeforeEach(func() { 119 otherAppName = helpers.PrefixedRandomName("app") 120 Eventually(helpers.CF("create-app", otherAppName)).Should(Exit(0)) 121 }) 122 123 It("errors saying the package does *not* exist", func() { 124 session := helpers.CF("stage-package", otherAppName, "--package-guid", packageGUID) 125 userName, _ := helpers.GetCredentials() 126 127 Eventually(session).Should(Say(`Staging package for %s in org %s / space %s as %s\.\.\.`, otherAppName, orgName, spaceName, userName)) 128 Eventually(session.Err).Should(Say(`Package with guid '%s' not found in app '%s'.`, packageGUID, otherAppName)) 129 130 Eventually(session).Should(Exit(1)) 131 }) 132 }) 133 }) 134 135 // TODO: remove flag from this sad path? 136 When("the app does not exist", func() { 137 It("displays app not found and exits 1", func() { 138 session := helpers.CF("stage-package", appName, "--package-guid", "some-package-guid") 139 userName, _ := helpers.GetCredentials() 140 141 Eventually(session).Should(Say(`Staging package for %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 142 Eventually(session.Err).Should(Say("App '%s' not found", appName)) 143 Eventually(session).Should(Say("FAILED")) 144 145 Eventually(session).Should(Exit(1)) 146 }) 147 }) 148 149 // TODO: remove flag from this sad path? 150 When("the package does not exist", func() { 151 BeforeEach(func() { 152 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 153 }) 154 155 It("displays package not found and exits 1", func() { 156 session := helpers.CF("stage-package", appName, "--package-guid", "some-package-guid") 157 userName, _ := helpers.GetCredentials() 158 159 Eventually(session).Should(Say(`Staging package for %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 160 Eventually(session.Err).Should(Say(`Package with guid '%s' not found in app '%s'.`, "some-package-guid", appName)) 161 Eventually(session).Should(Say("FAILED")) 162 Eventually(session).Should(Exit(1)) 163 }) 164 }) 165 }) 166 167 When("the package GUID flag is not provided", func() { 168 BeforeEach(func() { 169 Eventually(helpers.CF("create-app", appName)).Should(Exit(0)) 170 171 helpers.WithHelloWorldApp(func(appDir string) { 172 pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName) 173 Eventually(pkgSession).Should(Exit(0)) 174 }) 175 }) 176 177 It("stages the most recent package for the app", func() { 178 session := helpers.CF("stage-package", appName) 179 userName, _ := helpers.GetCredentials() 180 181 Eventually(session).Should(Say(`Staging package for %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 182 Eventually(session).Should(Say(`Downloading staticfile_buildpack\.\.\.`), "Error streaming logs") 183 Eventually(session).Should(Say(`Uploading droplet\.\.\.`), "Error streaming logs") 184 Eventually(session).Should(Say("Package staged")) 185 Eventually(session).Should(Say(`droplet guid:\s+%s`, helpers.GUIDRegex)) 186 Eventually(session).Should(Say(`state:\s+staged`)) 187 Eventually(session).Should(Say(`created:\s+%s`, helpers.UserFriendlyDateRegex)) 188 189 Eventually(session).Should(Exit(0)) 190 }) 191 }) 192 }) 193 })