From 0ba57a5936ed3ab34cc7e8331b55012ef13fdee2 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 24 Jan 2023 16:41:57 -0500 Subject: [PATCH] Fix AssertEncoderAgainstGoldenSnapshot calls to conditionally update (#1511) * fix AssertEncoderAgainstGoldenSnapshot calls to conditionally update Signed-off-by: Alex Goodman * chore: redact schema versions from syftjson comparison Signed-off-by: Keith Zantow * chore: does not need a multiline expression Signed-off-by: Keith Zantow Signed-off-by: Alex Goodman Signed-off-by: Keith Zantow Co-authored-by: Keith Zantow --- syft/formats/syftjson/encoder_test.go | 13 +++++++++++-- syft/formats/table/encoder_test.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/syft/formats/syftjson/encoder_test.go b/syft/formats/syftjson/encoder_test.go index 558fe2da6..216e60fc1 100644 --- a/syft/formats/syftjson/encoder_test.go +++ b/syft/formats/syftjson/encoder_test.go @@ -2,6 +2,7 @@ package syftjson import ( "flag" + "regexp" "testing" "github.com/anchore/syft/syft/artifact" @@ -20,8 +21,9 @@ func TestDirectoryEncoder(t *testing.T) { testutils.AssertEncoderAgainstGoldenSnapshot(t, Format(), testutils.DirectoryInput(t), - true, *updateJson, + true, + schemaVersionRedactor, ) } @@ -31,11 +33,18 @@ func TestImageEncoder(t *testing.T) { Format(), testutils.ImageInput(t, testImage, testutils.FromSnapshot()), testImage, - true, *updateJson, + true, + schemaVersionRedactor, ) } +func schemaVersionRedactor(s []byte) []byte { + pattern := regexp.MustCompile(`,?\s*"schema":\s*\{[^}]*}`) + out := pattern.ReplaceAll(s, []byte("")) + return out +} + func TestEncodeFullJSONDocument(t *testing.T) { catalog := pkg.NewCatalog() diff --git a/syft/formats/table/encoder_test.go b/syft/formats/table/encoder_test.go index ebce62e2d..830f28bb3 100644 --- a/syft/formats/table/encoder_test.go +++ b/syft/formats/table/encoder_test.go @@ -15,8 +15,8 @@ func TestTableEncoder(t *testing.T) { testutils.AssertEncoderAgainstGoldenSnapshot(t, Format(), testutils.DirectoryInput(t), - false, *updateTableGoldenFiles, + false, ) }