github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/formats/text/encoder_test.go (about) 1 package text 2 3 import ( 4 "flag" 5 "testing" 6 7 "github.com/anchore/syft/syft/formats/internal/testutils" 8 ) 9 10 var updateSnapshot = flag.Bool("update-text", false, "update the *.golden files for text encoder") 11 var updateImage = flag.Bool("update-image", false, "update the golden image used for image encoder testing") 12 13 func TestTextDirectoryEncoder(t *testing.T) { 14 dir := t.TempDir() 15 testutils.AssertEncoderAgainstGoldenSnapshot(t, 16 testutils.EncoderSnapshotTestConfig{ 17 Subject: testutils.DirectoryInput(t, dir), 18 Format: Format(), 19 UpdateSnapshot: *updateSnapshot, 20 PersistRedactionsInSnapshot: true, 21 IsJSON: false, 22 Redactor: redactor(dir), 23 }, 24 ) 25 } 26 27 func TestTextImageEncoder(t *testing.T) { 28 testImage := "image-simple" 29 testutils.AssertEncoderAgainstGoldenImageSnapshot(t, 30 testutils.ImageSnapshotTestConfig{ 31 Image: testImage, 32 UpdateImageSnapshot: *updateImage, 33 }, 34 testutils.EncoderSnapshotTestConfig{ 35 Subject: testutils.ImageInput(t, testImage, testutils.FromSnapshot()), 36 Format: Format(), 37 UpdateSnapshot: *updateSnapshot, 38 PersistRedactionsInSnapshot: true, 39 IsJSON: false, 40 Redactor: redactor(), 41 }, 42 ) 43 } 44 45 func redactor(values ...string) testutils.Redactor { 46 return testutils.NewRedactions(). 47 WithValuesRedacted(values...) 48 }