Skip to content

Commit 009aa85

Browse files
🌱 Unit tests for Vulnerabilities
- Unit tests for Vulnerabilities - #986
1 parent 05cedd7 commit 009aa85

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2022 Security Scorecard Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package evaluation
16+
17+
import (
18+
"testing"
19+
20+
"github.com/ossf/scorecard/v4/checker"
21+
scut "github.com/ossf/scorecard/v4/utests"
22+
)
23+
24+
// TestVulnerabilities tests the vulnerabilities checker.
25+
func TestVulnerabilities(t *testing.T) {
26+
t.Parallel()
27+
//nolint
28+
type args struct {
29+
name string
30+
r *checker.VulnerabilitiesData
31+
}
32+
tests := []struct {
33+
name string
34+
args args
35+
want checker.CheckResult
36+
expected []struct {
37+
lineNumber uint
38+
}
39+
}{
40+
{
41+
name: "no vulnerabilities",
42+
args: args{
43+
name: "vulnerabilities_test.go",
44+
r: &checker.VulnerabilitiesData{
45+
Vulnerabilities: []checker.Vulnerability{},
46+
},
47+
},
48+
want: checker.CheckResult{
49+
Score: 10,
50+
},
51+
},
52+
{
53+
name: "one vulnerability",
54+
args: args{
55+
name: "vulnerabilities_test.go",
56+
r: &checker.VulnerabilitiesData{
57+
Vulnerabilities: []checker.Vulnerability{
58+
{
59+
ID: "CVE-2019-1234",
60+
},
61+
},
62+
},
63+
},
64+
want: checker.CheckResult{
65+
Score: 9,
66+
},
67+
},
68+
{
69+
name: "one vulnerability",
70+
args: args{
71+
name: "vulnerabilities_test.go",
72+
},
73+
want: checker.CheckResult{
74+
Score: -1,
75+
},
76+
},
77+
}
78+
for _, tt := range tests {
79+
tt := tt
80+
t.Run(tt.name, func(t *testing.T) {
81+
t.Parallel()
82+
dl := scut.TestDetailLogger{}
83+
res := Vulnerabilities(tt.args.name, &dl, tt.args.r)
84+
if res.Score != tt.want.Score {
85+
t.Errorf("Vulnerabilities() = %v, want %v", res.Score, tt.want.Score)
86+
}
87+
})
88+
}
89+
}

0 commit comments

Comments
 (0)