Skip to content

Commit

Permalink
Add state to buildpacks output (cloudfoundry#2699)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippthun authored Dec 19, 2023
1 parent 7359fd7 commit ce44a4f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion command/v7/buildpacks_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (cmd BuildpacksCommand) Execute(args []string) error {
func (cmd BuildpacksCommand) displayTable(buildpacks []resources.Buildpack) {
if len(buildpacks) > 0 {
var keyValueTable = [][]string{
{"position", "name", "stack", "enabled", "locked", "filename"},
{"position", "name", "stack", "enabled", "locked", "state", "filename"},
}
for _, buildpack := range buildpacks {
keyValueTable = append(keyValueTable, []string{
Expand All @@ -57,6 +57,7 @@ func (cmd BuildpacksCommand) displayTable(buildpacks []resources.Buildpack) {
buildpack.Stack,
strconv.FormatBool(buildpack.Enabled.Value),
strconv.FormatBool(buildpack.Locked.Value),
buildpack.State,
buildpack.Filename,
})
}
Expand Down
9 changes: 6 additions & 3 deletions command/v7/buildpacks_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/commandfakes"
. "code.cloudfoundry.org/cli/command/v7"
"code.cloudfoundry.org/cli/command/v7/v7fakes"
Expand Down Expand Up @@ -114,6 +115,7 @@ var _ = Describe("buildpacks Command", func() {
Position: types.NullInt{Value: 1, IsSet: true},
Enabled: types.NullBool{Value: true, IsSet: true},
Locked: types.NullBool{Value: false, IsSet: true},
State: constant.BuildpackReady,
Filename: "buildpack-1.file",
Stack: "buildpack-1-stack",
},
Expand All @@ -123,6 +125,7 @@ var _ = Describe("buildpacks Command", func() {
Position: types.NullInt{Value: 2, IsSet: true},
Enabled: types.NullBool{Value: false, IsSet: true},
Locked: types.NullBool{Value: true, IsSet: true},
State: constant.BuildpackAwaitingUpload,
Filename: "buildpack-2.file",
Stack: "",
},
Expand All @@ -133,9 +136,9 @@ var _ = Describe("buildpacks Command", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(testUI.Err).To(Say("some-warning-1"))
Expect(testUI.Err).To(Say("some-warning-2"))
Expect(testUI.Out).To(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`))
Expect(testUI.Out).To(Say(`1\s+buildpack-1\s+buildpack-1-stack\s+true\s+false\s+buildpack-1.file`))
Expect(testUI.Out).To(Say(`2\s+buildpack-2\s+false\s+true\s+buildpack-2.file`))
Expect(testUI.Out).To(Say(`position\s+name\s+stack\s+enabled\s+locked\s+state\s+filename`))
Expect(testUI.Out).To(Say(`1\s+buildpack-1\s+buildpack-1-stack\s+true\s+false\s+READY\s+buildpack-1.file`))
Expect(testUI.Out).To(Say(`2\s+buildpack-2\s+false\s+true\s+AWAITING_UPLOAD\s+buildpack-2.file`))
})
})
When("there are no buildpacks", func() {
Expand Down
15 changes: 10 additions & 5 deletions integration/v7/isolated/buildpacks_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,36 @@ var _ = Describe("buildpacks command", func() {

username, _ := helpers.GetCredentials()
Eventually(session).Should(Say("Getting buildpacks as %s...", username))
Eventually(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`))
Eventually(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+state\s+filename`))

positionRegex := `\d+`
enabledRegex := `true`
lockedRegex := `false`
stackRegex := `(cflinuxfs[23]|windows.+)`
stateRegex := `READY`

staticfileNameRegex := `staticfile_buildpack`
// staticfileFileRegex := `staticfile[-_]buildpack-\S+`
staticfileFileRegex := ""
Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
positionRegex,
staticfileNameRegex,
stackRegex,
enabledRegex,
lockedRegex,
stateRegex,
staticfileFileRegex))

binaryNameRegex := `binary_buildpack`
// binaryFileRegex := `binary[-_]buildpack-\S+`
binaryFileRegex := ""
Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
positionRegex,
binaryNameRegex,
stackRegex,
enabledRegex,
lockedRegex,
stateRegex,
binaryFileRegex))
Eventually(session).Should(Exit(0))
})
Expand Down Expand Up @@ -118,7 +121,7 @@ var _ = Describe("buildpacks command", func() {

username, _ := helpers.GetCredentials()
Expect(session).Should(Say("Getting buildpacks as %s...", username))
Expect(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`))
Expect(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+state\s+filename`))

re := regexp.MustCompile(`(?:\n|\r)\d+\s+\w{8}`)
buildpackMatches := re.FindAll(session.Out.Contents(), -1)
Expand All @@ -128,13 +131,15 @@ var _ = Describe("buildpacks command", func() {
enabledRegex := `true`
lockedRegex := `false`
stackRegex := ``
stateRegex := `READY`

Expect(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
Expect(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
positionRegex,
buildpack2,
stackRegex,
enabledRegex,
lockedRegex,
stateRegex,
""))
})
})
Expand Down

0 comments on commit ce44a4f

Please sign in to comment.