github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/text/encoder_test.go (about)

     1  package text
     2  
     3  import (
     4  	"flag"
     5  	"testing"
     6  
     7  	"github.com/lineaje-labs/syft/syft/format/internal/testutil"
     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  	testutil.AssertEncoderAgainstGoldenSnapshot(t,
    16  		testutil.EncoderSnapshotTestConfig{
    17  			Subject:                     testutil.DirectoryInput(t, dir),
    18  			Format:                      NewFormatEncoder(),
    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  	testutil.AssertEncoderAgainstGoldenImageSnapshot(t,
    30  		testutil.ImageSnapshotTestConfig{
    31  			Image:               testImage,
    32  			UpdateImageSnapshot: *updateImage,
    33  		},
    34  		testutil.EncoderSnapshotTestConfig{
    35  			Subject:                     testutil.ImageInput(t, testImage, testutil.FromSnapshot()),
    36  			Format:                      NewFormatEncoder(),
    37  			UpdateSnapshot:              *updateSnapshot,
    38  			PersistRedactionsInSnapshot: true,
    39  			IsJSON:                      false,
    40  			Redactor:                    redactor(),
    41  		},
    42  	)
    43  }
    44  
    45  func redactor(values ...string) testutil.Redactor {
    46  	return testutil.NewRedactions().
    47  		WithValuesRedacted(values...)
    48  }