chore: add a test

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow 2025-02-25 10:26:45 -05:00
parent 823723f510
commit 7ea37792f1
No known key found for this signature in database
GPG Key ID: 735988DA57708682

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/format/internal/cyclonedxutil" "github.com/anchore/syft/syft/format/internal/cyclonedxutil"
"github.com/anchore/syft/syft/format/internal/testutil" "github.com/anchore/syft/syft/format/internal/testutil"
"github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg"
@ -27,6 +28,31 @@ func getEncoder(t testing.TB) sbom.FormatEncoder {
return enc return enc
} }
func Test_noTypedNils(t *testing.T) {
s := sbom.SBOM{
Artifacts: sbom.Artifacts{
FileMetadata: map[file.Coordinates]file.Metadata{},
FileDigests: map[file.Coordinates][]file.Digest{},
},
}
c := file.NewCoordinates("/dev/null", "123")
s.Artifacts.FileMetadata[c] = file.Metadata{
Path: "/dev/null",
}
s.Artifacts.FileDigests[c] = []file.Digest{}
enc, err := NewFormatEncoderWithConfig(EncoderConfig{
Version: "1.6",
Pretty: true,
})
require.NoError(t, err)
contents := bytes.Buffer{}
err = enc.Encode(&contents, s)
require.NoError(t, err)
require.NotContains(t, contents.String(), `"hashes": null`)
}
func TestPrettyOutput(t *testing.T) { func TestPrettyOutput(t *testing.T) {
run := func(opt bool) string { run := func(opt bool) string {
enc, err := NewFormatEncoderWithConfig(EncoderConfig{ enc, err := NewFormatEncoderWithConfig(EncoderConfig{