Skip to content

Commit

Permalink
Add check for missing dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Meyer <[email protected]>
Signed-off-by: Javier Romero <[email protected]>
  • Loading branch information
ameyer-pivotal authored and jromero committed Dec 19, 2019
1 parent 67d982a commit 29b4189
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/buildpackage/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (p *PackageBuilder) Save(repoName string, publish bool) (imgutil.Image, err
}
}

if len(stacks) == 0 {
return nil, errors.Errorf("no compatible stacks among provided buildpacks")
}

image, err := p.imageFactory.NewImage(repoName, !publish)
if err != nil {
return nil, errors.Wrapf(err, "creating image")
Expand Down
73 changes: 70 additions & 3 deletions internal/buildpackage/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -97,6 +97,30 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
})
})

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: 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, "no compatible stacks among provided buildpacks")
})
})

when("dependency does not have any matching stack", func() {
it("should error", func() {
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
Expand Down Expand Up @@ -179,7 +203,7 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
})

when("dependency is meta-buildpack", func() {
it("should succeed with common stacks", func() {
it("should succeed and compute common stacks", func() {
buildpack, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
API: api.MustParse("0.2"),
Info: dist.BuildpackInfo{
Expand Down Expand Up @@ -241,6 +265,49 @@ 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 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() {
Expand Down

0 comments on commit 29b4189

Please sign in to comment.