Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add one Rebase unit test and fix nil handling #1743

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/client/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ func (c *Client) Rebase(ctx context.Context, opts RebaseOptions) error {
return errors.Errorf("could not find label %s on image", style.Symbol(platform.LayerMetadataLabel))
}
var runImageMD builder.RunImageMetadata
if md.RunImage.Image != "" { // TODO: add unit
if md.RunImage.Image != "" {
runImageMD = builder.RunImageMetadata{
Image: md.RunImage.Image,
Mirrors: md.RunImage.Mirrors,
}
} else {
runImageMD = builder.RunImageMetadata{
Image: md.Stack.RunImage.Image,
Mirrors: md.Stack.RunImage.Mirrors,
if md.Stack != nil {
runImageMD = builder.RunImageMetadata{
Image: md.Stack.RunImage.Image,
Mirrors: md.Stack.RunImage.Mirrors,
}
}
}
runImageName := c.resolveRunImage(
Expand Down
17 changes: 17 additions & 0 deletions pkg/client/rebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ func testRebase(t *testing.T, when spec.G, it spec.S) {
h.AssertContains(t, lbl, `"runImage":{"topLayer":"local-mirror-top-layer-sha","reference":"local-mirror-digest"`)
})
})
when("there is a label and it has a run image and no stack", func() {
it("reads the run image from the label", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.lifecycle.metadata",
`{"runImage":{"image":"some/run", "mirrors":["example.com/some/run"]}}`))
h.AssertNil(t, subject.Rebase(context.TODO(), RebaseOptions{
RepoName: "some/app",
}))
h.AssertEq(t, fakeAppImage.Base(), "some/run")
})
})
when("there is neither runImage nor stack", func() {
it("fails gracefully", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.lifecycle.metadata", `{}`))
h.AssertError(t, subject.Rebase(context.TODO(), RebaseOptions{RepoName: "some/app"}),
"run image must be specified")
})
})
})

when("the image does not have a label with a run image specified", func() {
Expand Down