-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
classifier_test.go
101 lines (95 loc) · 2.33 KB
/
classifier_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package licensing_test
import (
"os"
"testing"
"github.com/aquasecurity/trivy/pkg/licensing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func TestClassifier_FullClassify(t *testing.T) {
tests := []struct {
name string
filePath string
want types.LicenseFile
wantErr assert.ErrorAssertionFunc
}{
{
name: "C file with AGPL-3.0",
filePath: "testdata/licensed.c",
want: types.LicenseFile{
Type: types.LicenseTypeHeader,
FilePath: "testdata/licensed.c",
Findings: []types.LicenseFinding{
{
Name: "AGPL-3.0",
Confidence: 1,
Link: "https://spdx.org/licenses/AGPL-3.0.html",
},
},
},
},
{
name: "C file with no license",
filePath: "testdata/unlicensed.c",
want: types.LicenseFile{
Type: types.LicenseTypeFile,
FilePath: "testdata/unlicensed.c",
},
},
{
name: "Creative commons License file",
filePath: "testdata/LICENSE_creativecommons",
want: types.LicenseFile{
Type: types.LicenseTypeFile,
FilePath: "testdata/LICENSE_creativecommons",
Findings: []types.LicenseFinding{
{
Name: "Commons-Clause",
Confidence: 1,
Link: "https://spdx.org/licenses/Commons-Clause.html",
},
},
},
},
{
name: "Apache-2.0 CSS File",
filePath: "testdata/styles.css",
want: types.LicenseFile{
Type: types.LicenseTypeFile,
FilePath: "testdata/styles.css",
Findings: []types.LicenseFinding{
{
Name: "Apache-2.0",
Confidence: 1,
Link: "https://spdx.org/licenses/Apache-2.0.html",
},
},
},
},
{
name: "Apache 2 License file",
filePath: "testdata/LICENSE_apache2",
want: types.LicenseFile{
Type: types.LicenseTypeFile,
FilePath: "testdata/LICENSE_apache2",
Findings: []types.LicenseFinding{
{
Name: "Apache-2.0",
Confidence: 1,
Link: "https://spdx.org/licenses/Apache-2.0.html",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
contents, err := os.ReadFile(tt.filePath)
require.NoError(t, err)
got, err := licensing.FullClassify(tt.filePath, contents)
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}