Skip to content

Commit

Permalink
Merge pull request #365 from buildpack/bugfix/null-bom
Browse files Browse the repository at this point in the history
fix inspect-image --bom when image is missing
  • Loading branch information
ekcasey authored Oct 22, 2019
2 parents 443a951 + e059ce8 commit c9cfac7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 9 additions & 2 deletions commands/inspect_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,16 @@ type bom struct {
}

func logBOM(remote *pack.ImageInfo, local *pack.ImageInfo, logger logging.Logger) error {
var remoteBOM, localBOM interface{}
if remote != nil {
remoteBOM = remote.BOM
}
if local != nil {
localBOM = local.BOM
}
rawBOM, err := json.Marshal(bom{
Remote: remote.BOM,
Local: local.BOM,
Remote: remoteBOM,
Local: localBOM,
})
if err != nil {
return errors.Wrapf(err, "writing bill of materials")
Expand Down
14 changes: 13 additions & 1 deletion commands/inspect_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ func testInspectImageCommand(t *testing.T, when spec.G, it spec.S) {

when("#InspectImage", func() {
when("image cannot be found", func() {
it("logs 'Not present'", func() {
it.Before(func() {
mockClient.EXPECT().InspectImage("some/image", false).Return(nil, nil)
mockClient.EXPECT().InspectImage("some/image", true).Return(nil, nil)
})

it("logs 'Not present'", func() {
h.AssertNil(t, command.Execute())

h.AssertContains(t, outBuf.String(), "REMOTE:\n(not present)\n\nLOCAL:\n(not present)\n")
})

when("--bom", func() {
it("adds nulls for missing images", func() {
command.SetArgs([]string{"some/image", "--bom"})
h.AssertNil(t, command.Execute())
h.AssertEq(t,
outBuf.String(),
`{"remote":null,"local":null}`+"\n")
})
})
})

when("inspector returns an error", func() {
Expand Down

0 comments on commit c9cfac7

Please sign in to comment.