Skip to content

Commit 9ec63b8

Browse files
committed
Set minimum cc version for lifecycle flag
Signed-off-by: Tom Kennedy <tom.kennedy@broadcom.com>
1 parent 0b96deb commit 9ec63b8

9 files changed

+96
-1
lines changed

api/cloudcontroller/ccversion/minimum_version.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const (
1212

1313
MinVersionLogRateLimitingV3 = "3.125.0"
1414
MinVersionPerRouteOpts = "3.183.0"
15+
16+
MinVersionBuildpackLifecycleQuery = "3.193.0" //todo: update this once the actual version is releasedMinVersionPerRouteOpts = "3.183.0"
1517

1618
MinVersionCanarySteps = "3.189.0"
1719
)

command/v7/buildpacks_command.go

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package v7
33
import (
44
"strconv"
55

6+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
7+
"code.cloudfoundry.org/cli/command"
68
"code.cloudfoundry.org/cli/resources"
79
"code.cloudfoundry.org/cli/util/ui"
810
)
@@ -27,6 +29,13 @@ func (cmd BuildpacksCommand) Execute(args []string) error {
2729
return err
2830
}
2931

32+
if cmd.Lifecycle != "" {
33+
err = command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionBuildpackLifecycleQuery, "--lifecycle")
34+
if err != nil {
35+
return err
36+
}
37+
}
38+
3039
cmd.UI.DisplayTextWithFlavor("Getting buildpacks as {{.Username}}...", map[string]interface{}{
3140
"Username": user.Name,
3241
})

command/v7/buildpacks_command_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.cloudfoundry.org/cli/actor/v7action"
1111
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
1212
"code.cloudfoundry.org/cli/command/commandfakes"
13+
"code.cloudfoundry.org/cli/command/translatableerror"
1314
. "code.cloudfoundry.org/cli/command/v7"
1415
"code.cloudfoundry.org/cli/command/v7/v7fakes"
1516
"code.cloudfoundry.org/cli/util/configv3"
@@ -35,6 +36,7 @@ var _ = Describe("buildpacks Command", func() {
3536
BeforeEach(func() {
3637
testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
3738
fakeConfig = new(commandfakes.FakeConfig)
39+
fakeConfig.APIVersionReturns("4.0.0")
3840
fakeSharedActor = new(commandfakes.FakeSharedActor)
3941
fakeActor = new(v7fakes.FakeActor)
4042
args = nil
@@ -101,6 +103,16 @@ var _ = Describe("buildpacks Command", func() {
101103
_, lifecycle := fakeActor.GetBuildpacksArgsForCall(0)
102104
Expect(lifecycle).To(Equal("cnb"))
103105
})
106+
It("fails when the cc version is below the minimum", func() {
107+
fakeConfig.APIVersionReturns("3.192.0")
108+
executeErr = cmd.Execute(nil)
109+
110+
Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
111+
Command: "--lifecycle",
112+
CurrentVersion: "3.192.0",
113+
MinimumVersion: "3.193.0",
114+
}))
115+
})
104116
})
105117

106118
When("getting buildpacks fails", func() {

command/v7/create_buildpack_command.go

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"code.cloudfoundry.org/cli/actor/v7action"
88
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
9+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
910
"code.cloudfoundry.org/cli/command"
1011
"code.cloudfoundry.org/cli/command/flag"
1112
"code.cloudfoundry.org/cli/command/translatableerror"
@@ -42,6 +43,13 @@ func (cmd CreateBuildpackCommand) Execute(args []string) error {
4243
return err
4344
}
4445

46+
if cmd.Lifecycle != "" {
47+
err = command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionBuildpackLifecycleQuery, "--lifecycle")
48+
if err != nil {
49+
return err
50+
}
51+
}
52+
4553
cmd.UI.DisplayTextWithFlavor("Creating buildpack {{.BuildpackName}} as {{.Username}}...", map[string]interface{}{
4654
"Username": user.Name,
4755
"BuildpackName": cmd.RequiredArgs.Buildpack,

command/v7/create_buildpack_command_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var _ = Describe("create buildpack Command", func() {
3939
BeforeEach(func() {
4040
testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
4141
fakeConfig = new(commandfakes.FakeConfig)
42+
fakeConfig.APIVersionReturns("4.0.0")
4243
fakeSharedActor = new(commandfakes.FakeSharedActor)
4344
fakeActor = new(v7fakes.FakeActor)
4445
args = nil
@@ -82,6 +83,23 @@ var _ = Describe("create buildpack Command", func() {
8283
})
8384
})
8485

86+
When("--lifecyle is provided", func() {
87+
JustBeforeEach(func() {
88+
cmd.Lifecycle = "some-lifecycle"
89+
fakeConfig.APIVersionReturns("3.192.0")
90+
})
91+
It("fails when the cc version is below the minimum", func() {
92+
executeErr = cmd.Execute(nil)
93+
94+
Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
95+
Command: "--lifecycle",
96+
CurrentVersion: "3.192.0",
97+
MinimumVersion: "3.193.0",
98+
}))
99+
})
100+
101+
})
102+
85103
When("the environment is setup correctly", func() {
86104
BeforeEach(func() {
87105
fakeActor.GetCurrentUserReturns(configv3.User{Name: "the-user"}, nil)

command/v7/delete_buildpack_command.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package v7
22

33
import (
44
"code.cloudfoundry.org/cli/actor/actionerror"
5+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
6+
"code.cloudfoundry.org/cli/command"
57
"code.cloudfoundry.org/cli/command/flag"
68
)
79

@@ -22,6 +24,13 @@ func (cmd DeleteBuildpackCommand) Execute(args []string) error {
2224
return err
2325
}
2426

27+
if cmd.Lifecycle != "" {
28+
err = command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionBuildpackLifecycleQuery, "--lifecycle")
29+
if err != nil {
30+
return err
31+
}
32+
}
33+
2534
if !cmd.Force {
2635
response, uiErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the {{.ModelType}} {{.ModelName}}?", map[string]interface{}{
2736
"ModelType": "buildpack",

command/v7/delete_buildpack_command_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"code.cloudfoundry.org/cli/actor/actionerror"
77
"code.cloudfoundry.org/cli/actor/v7action"
88
"code.cloudfoundry.org/cli/command/commandfakes"
9+
"code.cloudfoundry.org/cli/command/translatableerror"
910
. "code.cloudfoundry.org/cli/command/v7"
1011
"code.cloudfoundry.org/cli/command/v7/v7fakes"
1112
"code.cloudfoundry.org/cli/util/ui"
@@ -32,6 +33,7 @@ var _ = Describe("delete-buildpack Command", func() {
3233
input = NewBuffer()
3334
fakeActor = new(v7fakes.FakeActor)
3435
fakeConfig = new(commandfakes.FakeConfig)
36+
fakeConfig.APIVersionReturns("4.0.0")
3537
fakeSharedActor = new(commandfakes.FakeSharedActor)
3638
testUI = ui.NewTestUI(input, NewBuffer(), NewBuffer())
3739

@@ -50,6 +52,23 @@ var _ = Describe("delete-buildpack Command", func() {
5052
cmd.Force = true
5153
})
5254

55+
When("--lifecyle is provided", func() {
56+
JustBeforeEach(func() {
57+
cmd.Lifecycle = "some-lifecycle"
58+
fakeConfig.APIVersionReturns("3.192.0")
59+
})
60+
It("fails when the cc version is below the minimum", func() {
61+
executeErr = cmd.Execute(nil)
62+
63+
Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
64+
Command: "--lifecycle",
65+
CurrentVersion: "3.192.0",
66+
MinimumVersion: "3.193.0",
67+
}))
68+
})
69+
70+
})
71+
5372
When("checking target fails", func() {
5473
BeforeEach(func() {
5574
fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName})

command/v7/update_buildpack_command.go

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"code.cloudfoundry.org/cli/actor/v7action"
88
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
10+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
1011
"code.cloudfoundry.org/cli/command"
1112
"code.cloudfoundry.org/cli/command/flag"
1213
"code.cloudfoundry.org/cli/command/translatableerror"
@@ -56,6 +57,13 @@ func (cmd UpdateBuildpackCommand) Execute(args []string) error {
5657
return err
5758
}
5859

60+
if cmd.Lifecycle != "" {
61+
err = command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionBuildpackLifecycleQuery, "--lifecycle")
62+
if err != nil {
63+
return err
64+
}
65+
}
66+
5967
cmd.printInitialText(user.Name)
6068

6169
if cmd.Path != "" {

command/v7/update_buildpack_command_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var _ = Describe("UpdateBuildpackCommand", func() {
4444
testUI = ui.NewTestUI(input, NewBuffer(), NewBuffer())
4545
fakeActor = new(v7fakes.FakeActor)
4646
fakeConfig = new(commandfakes.FakeConfig)
47+
fakeConfig.APIVersionReturns("4.0.0")
4748
buildpackGUID = "some guid"
4849

4950
cmd = UpdateBuildpackCommand{
@@ -352,7 +353,16 @@ var _ = Describe("UpdateBuildpackCommand", func() {
352353
Expect(buildpack.Lifecycle).To(BeEmpty())
353354
Expect(lifecycleQuery).To(Equal("some-lifecycle"))
354355
})
355-
356+
It("fails when the cc version is below the minimum", func() {
357+
fakeConfig.APIVersionReturns("3.192.0")
358+
executeErr = cmd.Execute(nil)
359+
360+
Expect(executeErr).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
361+
Command: "--lifecycle",
362+
CurrentVersion: "3.192.0",
363+
MinimumVersion: "3.193.0",
364+
}))
365+
})
356366
})
357367

358368
When("the --rename flag is provided", func() {

0 commit comments

Comments
 (0)