Skip to content

Commit

Permalink
Support wildcard stacks in DependencyResolver
Browse files Browse the repository at this point in the history
DependencyResolver.Resolve will filter based on stack name. This was an exact match only.

This patch enabled DependencyResolver to match if a buildpack author has either set the wildcard stack (i.e. `*`) for a dependency or if a buildpack author has set no stack information (also treated as wildcard).

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
  • Loading branch information
Daniel Mikusa committed Sep 3, 2021
1 parent 26a8039 commit 8f10312
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
6 changes: 5 additions & 1 deletion buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,12 @@ func (d *DependencyResolver) Resolve(id string, version string) (BuildpackDepend
}

func (DependencyResolver) contains(candidates []string, value string) bool {
if len(candidates) == 0 {
return true
}

for _, c := range candidates {
if c == value {
if c == value || c == "*" {
return true
}
}
Expand Down
62 changes: 62 additions & 0 deletions buildpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,68 @@ func testBuildpack(t *testing.T, context spec.G, it spec.S) {
}))
})

it("filters by stack and supports the wildcard stack", func() {
resolver.Dependencies = []libpak.BuildpackDependency{
{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{"test-stack-1", "test-stack-2"},
},
{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{"*"},
},
}
resolver.StackID = "test-stack-3"

Expect(resolver.Resolve("test-id", "1.0")).To(Equal(libpak.BuildpackDependency{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{"*"},
}))
})

it("filters by stack and treats no stacks as the wildcard stack", func() {
resolver.Dependencies = []libpak.BuildpackDependency{
{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{"test-stack-1", "test-stack-2"},
},
{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{},
},
}
resolver.StackID = "test-stack-3"

Expect(resolver.Resolve("test-id", "1.0")).To(Equal(libpak.BuildpackDependency{
ID: "test-id",
Name: "test-name",
Version: "1.0",
URI: "test-uri",
SHA256: "test-sha256",
Stacks: []string{},
}))
})

it("returns the best dependency", func() {
resolver.Dependencies = []libpak.BuildpackDependency{
{
Expand Down

0 comments on commit 8f10312

Please sign in to comment.