Skip to content

Commit

Permalink
Merge pull request #82 from paketo-buildpacks/wildcard
Browse files Browse the repository at this point in the history
Support wildcard stacks in DependencyResolver
  • Loading branch information
Daniel Mikusa authored Sep 3, 2021
2 parents 26a8039 + 8f10312 commit 1e26710
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 1e26710

Please sign in to comment.