mirror of
https://github.com/anchore/syft.git
synced 2026-04-01 14:43:29 +02:00
* refactor source API and syft json source block Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update source detection and format test utils Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * generate list of all source metadata types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * extract base and root normalization into helper functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * preserve syftjson model package name import ref Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * alias should not be a pointer Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package template
|
|
|
|
import (
|
|
"flag"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/anchore/syft/syft/formats/internal/testutils"
|
|
)
|
|
|
|
var updateSnapshot = flag.Bool("update-template", false, "update the *.golden files for json encoders")
|
|
|
|
func TestFormatWithOption(t *testing.T) {
|
|
f := OutputFormat{}
|
|
f.SetTemplatePath("test-fixtures/csv.template")
|
|
|
|
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
|
testutils.EncoderSnapshotTestConfig{
|
|
Subject: testutils.DirectoryInput(t, t.TempDir()),
|
|
Format: f,
|
|
UpdateSnapshot: *updateSnapshot,
|
|
PersistRedactionsInSnapshot: true,
|
|
IsJSON: false,
|
|
},
|
|
)
|
|
}
|
|
|
|
func TestFormatWithOptionAndHasField(t *testing.T) {
|
|
f := OutputFormat{}
|
|
f.SetTemplatePath("test-fixtures/csv-hasField.template")
|
|
|
|
testutils.AssertEncoderAgainstGoldenSnapshot(t,
|
|
testutils.EncoderSnapshotTestConfig{
|
|
Subject: testutils.DirectoryInputWithAuthorField(t),
|
|
Format: f,
|
|
UpdateSnapshot: *updateSnapshot,
|
|
PersistRedactionsInSnapshot: true,
|
|
IsJSON: false,
|
|
},
|
|
)
|
|
|
|
}
|
|
|
|
func TestFormatWithoutOptions(t *testing.T) {
|
|
f := Format()
|
|
err := f.Encode(nil, testutils.DirectoryInput(t, t.TempDir()))
|
|
assert.ErrorContains(t, err, "no template file: please provide a template path")
|
|
}
|