diff --git a/buildpack.go b/buildpack.go index c0c0055..e6584e6 100644 --- a/buildpack.go +++ b/buildpack.go @@ -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 } } diff --git a/buildpack_test.go b/buildpack_test.go index 5bc9844..fc69f6b 100644 --- a/buildpack_test.go +++ b/buildpack_test.go @@ -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{ {