github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/syft/formats/common/spdxhelpers/document_namespace_test.go (about) 1 package spdxhelpers 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 "github.com/kastenhq/syft/syft/internal/sourcemetadata" 11 "github.com/kastenhq/syft/syft/source" 12 ) 13 14 func Test_documentNamespace(t *testing.T) { 15 tracker := sourcemetadata.NewCompletionTester(t) 16 17 tests := []struct { 18 name string 19 inputName string 20 src source.Description 21 expected string 22 }{ 23 { 24 name: "image", 25 inputName: "my-name", 26 src: source.Description{ 27 Metadata: source.StereoscopeImageSourceMetadata{ 28 UserInput: "image-repo/name:tag", 29 ID: "id", 30 ManifestDigest: "digest", 31 }, 32 }, 33 expected: "https://anchore.com/syft/image/my-name-", 34 }, 35 { 36 name: "directory", 37 inputName: "my-name", 38 src: source.Description{ 39 Metadata: source.DirectorySourceMetadata{ 40 Path: "some/path/to/place", 41 }, 42 }, 43 expected: "https://anchore.com/syft/dir/my-name-", 44 }, 45 { 46 name: "file", 47 inputName: "my-name", 48 src: source.Description{ 49 Metadata: source.FileSourceMetadata{ 50 Path: "some/path/to/place", 51 }, 52 }, 53 expected: "https://anchore.com/syft/file/my-name-", 54 }, 55 } 56 for _, test := range tests { 57 t.Run(test.name, func(t *testing.T) { 58 actual := DocumentNamespace(test.inputName, test.src) 59 // note: since the namespace ends with a UUID we check the prefix 60 assert.True(t, strings.HasPrefix(actual, test.expected), fmt.Sprintf("actual namespace %q", actual)) 61 62 // track each scheme tested (passed or not) 63 tracker.Tested(t, test.src.Metadata) 64 }) 65 } 66 }