Skip to content

Commit 57a1b47

Browse files
jfeenycf-buildpacks-eng
authored andcommitted
delete/update-buildpack now accept [-s STACK] to disambiguate buildpacks with same name
[#153256959] Signed-off-by: Sam Coward <[email protected]> Signed-off-by: Jackson Feeny <[email protected]> Signed-off-by: Victoria Henry <[email protected]>
1 parent 6348f97 commit 57a1b47

23 files changed

+967
-87
lines changed

cf/api/apifakes/fake_buildpack_repository.go

Lines changed: 183 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cf/api/apifakes/old_fake_buildpack_repo.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package apifakes
22

33
import (
4+
"fmt"
5+
46
"code.cloudfoundry.org/cli/cf/errors"
57
"code.cloudfoundry.org/cli/cf/models"
68
)
@@ -12,6 +14,12 @@ type OldFakeBuildpackRepository struct {
1214
FindByNameName string
1315
FindByNameBuildpack models.Buildpack
1416
FindByNameAPIResponse error
17+
FindByNameAmbiguous bool
18+
19+
FindByNameAndStackNotFound bool
20+
FindByNameAndStackName string
21+
FindByNameAndStackStack string
22+
FindByNameAndStackBuildpack models.Buildpack
1523

1624
CreateBuildpackExists bool
1725
CreateBuildpack models.Buildpack
@@ -42,17 +50,34 @@ func (repo *OldFakeBuildpackRepository) FindByName(name string) (buildpack model
4250

4351
if repo.FindByNameNotFound {
4452
apiErr = errors.NewModelNotFoundError("Buildpack", name)
53+
} else if repo.FindByNameAmbiguous {
54+
apiErr = errors.NewAmbiguousModelError("Buildpack", name)
55+
}
56+
57+
return
58+
}
59+
60+
func (repo *OldFakeBuildpackRepository) FindByNameAndStack(name, stack string) (buildpack models.Buildpack, apiErr error) {
61+
repo.FindByNameAndStackName = name
62+
repo.FindByNameAndStackStack = stack
63+
buildpack = repo.FindByNameAndStackBuildpack
64+
65+
if repo.FindByNameAndStackNotFound {
66+
apiErr = errors.NewModelNotFoundError("Buildpack", name)
4567
}
4668

4769
return
4870
}
4971

72+
var buildpackCreateCount int
73+
5074
func (repo *OldFakeBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack models.Buildpack, apiErr error) {
5175
if repo.CreateBuildpackExists {
5276
return repo.CreateBuildpack, errors.NewHTTPError(400, errors.BuildpackNameTaken, "Buildpack already exists")
5377
}
5478

55-
repo.CreateBuildpack = models.Buildpack{Name: name, Position: position, Enabled: enabled, Locked: locked}
79+
repo.CreateBuildpack = models.Buildpack{Name: name, Position: position, Enabled: enabled, Locked: locked, GUID: fmt.Sprintf("BUILDPACK-GUID-%d", buildpackCreateCount)}
80+
buildpackCreateCount++
5681
return repo.CreateBuildpack, repo.CreateAPIResponse
5782
}
5883

0 commit comments

Comments
 (0)