From 7ea37792f1533625a833da99790653bf3910b74a Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Tue, 25 Feb 2025 10:26:45 -0500 Subject: [PATCH] chore: add a test Signed-off-by: Keith Zantow --- syft/format/cyclonedxjson/encoder_test.go | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/syft/format/cyclonedxjson/encoder_test.go b/syft/format/cyclonedxjson/encoder_test.go index 90af61412..12b8e72a8 100644 --- a/syft/format/cyclonedxjson/encoder_test.go +++ b/syft/format/cyclonedxjson/encoder_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "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/testutil" "github.com/anchore/syft/syft/pkg" @@ -27,6 +28,31 @@ func getEncoder(t testing.TB) sbom.FormatEncoder { 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) { run := func(opt bool) string { enc, err := NewFormatEncoderWithConfig(EncoderConfig{