mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Fix AssertEncoderAgainstGoldenSnapshot calls to conditionally update (#1511)
* fix AssertEncoderAgainstGoldenSnapshot calls to conditionally update Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * chore: redact schema versions from syftjson comparison Signed-off-by: Keith Zantow <kzantow@gmail.com> * chore: does not need a multiline expression Signed-off-by: Keith Zantow <kzantow@gmail.com> Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Keith Zantow <kzantow@gmail.com> Co-authored-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
parent
3269bc98d4
commit
0ba57a5936
@ -2,6 +2,7 @@ package syftjson
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
@ -20,8 +21,9 @@ func TestDirectoryEncoder(t *testing.T) {
|
|||||||
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
||||||
Format(),
|
Format(),
|
||||||
testutils.DirectoryInput(t),
|
testutils.DirectoryInput(t),
|
||||||
true,
|
|
||||||
*updateJson,
|
*updateJson,
|
||||||
|
true,
|
||||||
|
schemaVersionRedactor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,11 +33,18 @@ func TestImageEncoder(t *testing.T) {
|
|||||||
Format(),
|
Format(),
|
||||||
testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
|
testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
|
||||||
testImage,
|
testImage,
|
||||||
true,
|
|
||||||
*updateJson,
|
*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) {
|
func TestEncodeFullJSONDocument(t *testing.T) {
|
||||||
catalog := pkg.NewCatalog()
|
catalog := pkg.NewCatalog()
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ func TestTableEncoder(t *testing.T) {
|
|||||||
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
||||||
Format(),
|
Format(),
|
||||||
testutils.DirectoryInput(t),
|
testutils.DirectoryInput(t),
|
||||||
false,
|
|
||||||
*updateTableGoldenFiles,
|
*updateTableGoldenFiles,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user