Skip to content

Commit

Permalink
Do not assume buildpack id ends with -buildpacks
Browse files Browse the repository at this point in the history
The package id regular expression assumes that the package ID will be `<something>-buildpacks/<id>`. This works for `paketo-buildpacks/` and `tanzu-buildpacks/`. It does not work for the `paketocommunity`.

This commit modifes the regular expression to permit anything in the form `<something>/<id>`, which matches previous patterns plus `paketocommunity/` as well.

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
  • Loading branch information
Daniel Mikusa committed Sep 28, 2021
1 parent 7f7ad2d commit 5340782
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion carton/package_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
PackageIdDependencyPattern = `(?m)(.*id[\s]+=[\s]+".+-buildpacks/%s",[\s]+version=")[^"]+(".*)`
PackageIdDependencyPattern = `(?m)(.*id[\s]+=[\s]+".+/%s",[\s]+version=")[^"]+(".*)`
PackageImageDependencyPattern = `(?m)(.*uri[\s]+=[\s]+".*%s:)[^"]+(".*)`
PackageDependencySubstitution = "${1}%s${2}"
)
Expand Down
44 changes: 42 additions & 2 deletions carton/package_dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func testPackageDependency(t *testing.T, context spec.G, it spec.S) {
Expect(os.RemoveAll(path)).To(Succeed())
})

it("updates buildpack dependency", func() {
it("updates paketo-buildpacks dependency", func() {
Expect(ioutil.WriteFile(path, []byte(`
{ id = "paketo-buildpacks/test-1", version="test-version-1" },
{ id = "paketo-buildpacks/test-2", version="test-version-2" },
Expand All @@ -73,6 +73,26 @@ func testPackageDependency(t *testing.T, context spec.G, it spec.S) {
`)))
})

it("updates paketocommunity dependency", func() {
Expect(ioutil.WriteFile(path, []byte(`
{ id = "paketocommunity/test-1", version="test-version-1" },
{ id = "paketocommunity/test-2", version="test-version-2" },
`), 0644)).To(Succeed())

p := carton.PackageDependency{
BuildpackPath: path,
ID: "docker.io/paketocommunity/test-1",
Version: "test-version-3",
}

p.Update(carton.WithExitHandler(exitHandler))

Expect(ioutil.ReadFile(path)).To(Equal([]byte(`
{ id = "paketocommunity/test-1", version="test-version-3" },
{ id = "paketocommunity/test-2", version="test-version-2" },
`)))
})

it("updates builder dependency", func() {
Expect(ioutil.WriteFile(path, []byte(`
{ id = "paketo-buildpacks/test-1", uri = "docker://gcr.io/paketo-buildpacks/test-1:test-version-1" },
Expand All @@ -93,7 +113,7 @@ func testPackageDependency(t *testing.T, context spec.G, it spec.S) {
`)))
})

it("updates package dependency", func() {
it("updates paketo-buildpacks package dependency", func() {
Expect(ioutil.WriteFile(path, []byte(`
{ uri = "docker://gcr.io/paketo-buildpacks/test-1:test-version-1" },
{ uri = "docker://gcr.io/paketo-buildpacks/test-2:test-version-2" },
Expand All @@ -110,6 +130,26 @@ func testPackageDependency(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.ReadFile(path)).To(Equal([]byte(`
{ uri = "docker://gcr.io/paketo-buildpacks/test-1:test-version-3" },
{ uri = "docker://gcr.io/paketo-buildpacks/test-2:test-version-2" },
`)))
})

it("updates paketocommunity package dependency", func() {
Expect(ioutil.WriteFile(path, []byte(`
{ uri = "docker://docker.io/paketocommunity/test-1:test-version-1" },
{ uri = "docker://docker.io/paketocommunity/test-2:test-version-2" },
`), 0644)).To(Succeed())

p := carton.PackageDependency{
PackagePath: path,
ID: "docker.io/paketocommunity/test-1",
Version: "test-version-3",
}

p.Update(carton.WithExitHandler(exitHandler))

Expect(ioutil.ReadFile(path)).To(Equal([]byte(`
{ uri = "docker://docker.io/paketocommunity/test-1:test-version-3" },
{ uri = "docker://docker.io/paketocommunity/test-2:test-version-2" },
`)))
})

Expand Down

0 comments on commit 5340782

Please sign in to comment.