github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/buildpacks_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 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 ) 13 14 var _ = Describe("buildpacks command", func() { 15 When("--help is passed", func() { 16 It("appears in cf help -a", func() { 17 session := helpers.CF("help", "-a") 18 Eventually(session).Should(Exit(0)) 19 Expect(session).To(HaveCommandInCategoryWithDescription("buildpacks", "BUILDPACKS", "List all buildpacks")) 20 }) 21 22 It("displays the help message", func() { 23 session := helpers.CF("buildpacks", "--help") 24 Eventually(session).Should(Say("NAME:")) 25 Eventually(session).Should(Say("buildpacks - List all buildpacks")) 26 Eventually(session).Should(Say("USAGE:")) 27 Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks [--labels SELECTOR]"))) 28 Eventually(session).Should(Say("EXAMPLES:")) 29 Eventually(session).Should(Say("cf buildpacks")) 30 Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks --labels 'environment in (production,staging),tier in (backend)'"))) 31 Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks --labels 'env=dev,!chargeback-code,tier in (backend,worker)'"))) 32 Eventually(session).Should(Say("OPTIONS:")) 33 Eventually(session).Should(Say(`--labels\s+Selector to filter buildpacks by labels`)) 34 Eventually(session).Should(Say("SEE ALSO:")) 35 Eventually(session).Should(Say("create-buildpack, delete-buildpack, rename-buildpack, update-buildpack")) 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 40 When("environment is not set up", func() { 41 It("displays an error and exits 1", func() { 42 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "buildpacks") 43 }) 44 }) 45 46 When("the targeted API supports stack association", func() { 47 BeforeEach(func() { 48 helpers.LoginCF() 49 }) 50 51 It("lists the buildpacks with the stack column", func() { 52 session := helpers.CF("buildpacks") 53 54 username, _ := helpers.GetCredentials() 55 Eventually(session).Should(Say("Getting buildpacks as %s...", username)) 56 Eventually(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`)) 57 58 positionRegex := `\d+` 59 enabledRegex := `true` 60 lockedRegex := `false` 61 stackRegex := `(cflinuxfs[23]|windows.+)` 62 63 staticfileNameRegex := `staticfile_buildpack` 64 // staticfileFileRegex := `staticfile[-_]buildpack-\S+` 65 staticfileFileRegex := "" 66 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, 67 positionRegex, 68 staticfileNameRegex, 69 stackRegex, 70 enabledRegex, 71 lockedRegex, 72 staticfileFileRegex)) 73 74 binaryNameRegex := `binary_buildpack` 75 // binaryFileRegex := `binary[-_]buildpack-\S+` 76 binaryFileRegex := "" 77 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, 78 positionRegex, 79 binaryNameRegex, 80 stackRegex, 81 enabledRegex, 82 lockedRegex, 83 binaryFileRegex)) 84 Eventually(session).Should(Exit(0)) 85 }) 86 87 When("the --labels flag is given", func() { 88 When("the --labels selector is malformed", func() { 89 It("errors", func() { 90 session := helpers.CF("buildpacks", "--labels", "malformed in (") 91 Eventually(session).Should(Exit(1)) 92 }) 93 }) 94 95 When("there are buildpacks with labels", func() { 96 var ( 97 buildpack1 string 98 buildpack2 string 99 ) 100 101 BeforeEach(func() { 102 buildpack1 = helpers.NewBuildpackName() 103 buildpack2 = helpers.NewBuildpackName() 104 helpers.SetupBuildpackWithoutStack(buildpack1) 105 helpers.SetupBuildpackWithoutStack(buildpack2) 106 Eventually(helpers.CF("set-label", "buildpack", buildpack1, "environment=production", "tier=backend")).Should(Exit(0)) 107 Eventually(helpers.CF("set-label", "buildpack", buildpack2, "environment=staging", "tier=frontend")).Should(Exit(0)) 108 }) 109 110 AfterEach(func() { 111 Eventually(helpers.CF("delete-buildpack", buildpack1, "-f")).Should(Exit(0)) 112 Eventually(helpers.CF("delete-buildpack", buildpack2, "-f")).Should(Exit(0)) 113 }) 114 115 It("lists the filtered buildpacks", func() { 116 session := helpers.CF("buildpacks", "--labels", "tier=frontend") 117 Eventually(session).Should(Exit(0)) 118 119 username, _ := helpers.GetCredentials() 120 Expect(session).Should(Say("Getting buildpacks as %s...", username)) 121 Expect(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`)) 122 123 re := regexp.MustCompile(`(?:\n|\r)\d+\s+\w{8}`) 124 buildpackMatches := re.FindAll(session.Out.Contents(), -1) 125 Expect(len(buildpackMatches)).To(Equal(1)) 126 127 positionRegex := `\d+` 128 enabledRegex := `true` 129 lockedRegex := `false` 130 stackRegex := `` 131 132 Expect(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, 133 positionRegex, 134 buildpack2, 135 stackRegex, 136 enabledRegex, 137 lockedRegex, 138 "")) 139 }) 140 }) 141 }) 142 }) 143 })