mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* split up sbom.Format into encode and decode ops Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update cmd pkg to inject format configs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * bump cyclonedx schema to 1.5 Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * redact image metadata from github encoder tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add more testing around format decoder identify Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add test case for format version options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix CLI test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] - review comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep encoder creation out of post load function Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep decider and identify functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add a few more doc comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove format encoder default function helpers Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * move back to streaming based decode functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * with common convention for encoder constructors Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests and allow for encoders to be created from cli options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * buffer reads from stdin to support seeking Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package spdxhelpers
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/anchore/syft/syft/internal/sourcemetadata"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
func Test_documentNamespace(t *testing.T) {
|
|
tracker := sourcemetadata.NewCompletionTester(t)
|
|
|
|
tests := []struct {
|
|
name string
|
|
inputName string
|
|
src source.Description
|
|
expected string
|
|
}{
|
|
{
|
|
name: "image",
|
|
inputName: "my-name",
|
|
src: source.Description{
|
|
Metadata: source.StereoscopeImageSourceMetadata{
|
|
UserInput: "image-repo/name:tag",
|
|
ID: "id",
|
|
ManifestDigest: "digest",
|
|
},
|
|
},
|
|
expected: "https://anchore.com/syft/image/my-name-",
|
|
},
|
|
{
|
|
name: "directory",
|
|
inputName: "my-name",
|
|
src: source.Description{
|
|
Metadata: source.DirectorySourceMetadata{
|
|
Path: "some/path/to/place",
|
|
},
|
|
},
|
|
expected: "https://anchore.com/syft/dir/my-name-",
|
|
},
|
|
{
|
|
name: "file",
|
|
inputName: "my-name",
|
|
src: source.Description{
|
|
Metadata: source.FileSourceMetadata{
|
|
Path: "some/path/to/place",
|
|
},
|
|
},
|
|
expected: "https://anchore.com/syft/file/my-name-",
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
actual := DocumentNamespace(test.inputName, test.src, sbom.Descriptor{
|
|
Name: "syft",
|
|
})
|
|
|
|
// note: since the namespace ends with a UUID we check the prefix
|
|
assert.True(t, strings.HasPrefix(actual, test.expected), fmt.Sprintf("expected prefix: '%s' got: '%s'", test.expected, actual))
|
|
|
|
// track each scheme tested (passed or not)
|
|
tracker.Tested(t, test.src.Metadata)
|
|
})
|
|
}
|
|
}
|