forked from anchore/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
language_test.go
66 lines (56 loc) · 1.27 KB
/
language_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pkg
import (
"github.com/scylladb/go-set/strset"
"github.com/stretchr/testify/assert"
"testing"
)
func TestLanguageFromPURL(t *testing.T) {
tests := []struct {
purl string
want Language
}{
{
purl: "pkg:npm/util@2.32",
want: JavaScript,
},
{
purl: "pkg:pypi/util-linux@2.32.1-27.el8",
want: Python,
},
{
purl: "pkg:gem/ruby-advisory-db-check@0.12.4",
want: Ruby,
},
{
purl: "pkg:golang/github.com/gorilla/context@234fd47e07d1004f0aed9c",
want: Go,
},
{
purl: "pkg:cargo/clap@2.33.0",
want: Rust,
},
{
purl: "pkg:composer/laravel/laravel@5.5.0",
want: PHP,
},
{
purl: "pkg:maven/org.apache.xmlgraphics/batik-anim@1.9.1?type=zip&classifier=dist",
want: Java,
},
}
var languages []string
var expectedLanguages = strset.New()
for _, ty := range AllLanguages {
expectedLanguages.Add(string(ty))
}
for _, tt := range tests {
t.Run(tt.purl, func(t *testing.T) {
actual := LanguageFromPURL(tt.purl)
if actual != "" {
languages = append(languages, string(actual))
}
assert.Equalf(t, tt.want, actual, "LanguageFromPURL(%v)", tt.purl)
})
}
assert.ElementsMatch(t, expectedLanguages.List(), languages, "missing one or more languages to test against (maybe a package type was added?)")
}