-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from buildpacks/fix/289-package-meta-buildpack
Fix: support meta-buildpack in packages
- Loading branch information
Showing
2 changed files
with
172 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,8 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { | |
}) | ||
|
||
when("#Save", func() { | ||
when("validate default", func() { | ||
when("default not set", func() { | ||
when("validate buildpack", func() { | ||
when("buildpack not set", func() { | ||
it("returns error", func() { | ||
_, err := subject.Save(fakePackageImage.Name(), false) | ||
h.AssertError(t, err, "buildpack must be set") | ||
|
@@ -58,22 +58,66 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { | |
}) | ||
|
||
when("validate stacks", func() { | ||
when("buildpack doesn't have a declared stack", func() { | ||
it("should error", func() { | ||
when("buildpack is meta-buildpack", func() { | ||
it("should succeed", func() { | ||
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.1.id", | ||
Version: "bp.1.version", | ||
}, | ||
Stacks: nil, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.nested.id", Version: "bp.nested.version"}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.SetBuildpack(buildpack) | ||
|
||
dependency, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.nested.id", | ||
Version: "bp.nested.version", | ||
}, | ||
Stacks: []dist.Stack{ | ||
{ID: "stack.id.1", Mixins: []string{"Mixin-A"}}, | ||
}, | ||
Order: nil, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.AddDependency(dependency) | ||
|
||
_, err = subject.Save("some/package", false) | ||
h.AssertNil(t, err) | ||
}) | ||
}) | ||
|
||
when("buildpack is meta-buildpack and its dependency is missing", func() { | ||
it("should return an error", func() { | ||
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.1.id", | ||
Version: "bp.1.version", | ||
}, | ||
Stacks: nil, | ||
Order: nil, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.nested.id", Version: "bp.nested.version"}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.SetBuildpack(buildpack) | ||
|
||
_, err = subject.Save("some/package", false) | ||
h.AssertError(t, err, "buildpack '[email protected]' must support at least one stack") | ||
h.AssertError(t, err, "no compatible stacks among provided buildpacks") | ||
}) | ||
}) | ||
|
||
|
@@ -157,6 +201,113 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { | |
h.AssertEq(t, metadata.Stacks, []dist.Stack{{ID: "stack.id.1", Mixins: []string{"Mixin-A"}}}) | ||
}) | ||
}) | ||
|
||
when("dependency is meta-buildpack", func() { | ||
it("should succeed and compute common stacks", func() { | ||
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.1.id", | ||
Version: "bp.1.version", | ||
}, | ||
Stacks: nil, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.nested.id", Version: "bp.nested.version"}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.SetBuildpack(buildpack) | ||
|
||
dependencyOrder, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.nested.id", | ||
Version: "bp.nested.version", | ||
}, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ | ||
ID: "bp.nested.nested.id", | ||
Version: "bp.nested.nested.version", | ||
}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.AddDependency(dependencyOrder) | ||
|
||
dependencyNestedNested, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.nested.nested.id", | ||
Version: "bp.nested.nested.version", | ||
}, | ||
Stacks: []dist.Stack{ | ||
{ID: "stack.id.1", Mixins: []string{"Mixin-A"}}, | ||
}, | ||
Order: nil, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.AddDependency(dependencyNestedNested) | ||
|
||
img, err := subject.Save("some/package", false) | ||
h.AssertNil(t, err) | ||
|
||
metadata := buildpackage.Metadata{} | ||
_, err = dist.GetLabel(img, "io.buildpacks.buildpackage.metadata", &metadata) | ||
h.AssertNil(t, err) | ||
|
||
h.AssertEq(t, metadata.Stacks, []dist.Stack{{ID: "stack.id.1", Mixins: []string{"Mixin-A"}}}) | ||
}) | ||
}) | ||
|
||
when("dependency is meta-buildpack and its dependency is missing", func() { | ||
it("should return an error", func() { | ||
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.1.id", | ||
Version: "bp.1.version", | ||
}, | ||
Stacks: nil, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.nested.id", Version: "bp.nested.version"}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.SetBuildpack(buildpack) | ||
|
||
dependencyOrder, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ | ||
API: api.MustParse("0.2"), | ||
Info: dist.BuildpackInfo{ | ||
ID: "bp.nested.id", | ||
Version: "bp.nested.version", | ||
}, | ||
Order: dist.Order{{ | ||
Group: []dist.BuildpackRef{ | ||
{BuildpackInfo: dist.BuildpackInfo{ | ||
ID: "bp.nested.nested.id", | ||
Version: "bp.nested.nested.version", | ||
}}, | ||
}, | ||
}}, | ||
}, 0644) | ||
h.AssertNil(t, err) | ||
|
||
subject.AddDependency(dependencyOrder) | ||
|
||
_, err = subject.Save("some/package", false) | ||
h.AssertError(t, err, "no compatible stacks among provided buildpacks") | ||
}) | ||
}) | ||
}) | ||
|
||
it("sets metadata", func() { | ||
|