Skip to content

Commit

Permalink
fix: empty descriptor name and version (#1542)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow authored Oct 6, 2023
1 parent 548da9e commit 8ebf295
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/grype/cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func runGrype(app clio.Application, opts *options.Grype, userInput string) (errs
}

if err = writer.Write(models.PresenterConfig{
ID: app.ID(),
Matches: *remainingMatches,
IgnoredMatches: ignoredMatches,
Packages: packages,
Expand Down
20 changes: 20 additions & 0 deletions test/cli/cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cli

import (
"encoding/json"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestCmd(t *testing.T) {
Expand Down Expand Up @@ -78,3 +81,20 @@ func TestCmd(t *testing.T) {
})
}
}

func Test_descriptorNameAndVersionSet(t *testing.T) {
_, output, _ := runGrype(t, nil, "-o", "json", getFixtureImage(t, "image-bare"))

parsed := map[string]any{}
err := json.Unmarshal([]byte(output), &parsed)
require.NoError(t, err)

desc, _ := parsed["descriptor"].(map[string]any)
require.NotNil(t, desc)

name := desc["name"]
require.Equal(t, "grype", name)

version := desc["version"]
require.NotEmpty(t, version)
}

0 comments on commit 8ebf295

Please sign in to comment.