Skip to content

Commit

Permalink
Merge pull request #1743 from joe-kimmel-vmw/jkutner/dep-updates
Browse files Browse the repository at this point in the history
add one Rebase unit test and fix nil handling
  • Loading branch information
natalieparellano authored Apr 28, 2023
2 parents 85da68a + 6b17d90 commit 8e03c74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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

0 comments on commit 8e03c74

Please sign in to comment.