Skip to content

Commit

Permalink
🌱 Unit tests for Vulnerabilities
Browse files Browse the repository at this point in the history
- Unit tests for Vulnerabilities
- #986
  • Loading branch information
naveensrinivasan committed Feb 2, 2022
1 parent 05cedd7 commit 009aa85
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions checks/evaluation/vulnerabilities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2022 Security Scorecard Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package evaluation

import (
"testing"

"github.com/ossf/scorecard/v4/checker"
scut "github.com/ossf/scorecard/v4/utests"
)

// TestVulnerabilities tests the vulnerabilities checker.
func TestVulnerabilities(t *testing.T) {
t.Parallel()
//nolint
type args struct {
name string
r *checker.VulnerabilitiesData
}
tests := []struct {
name string
args args
want checker.CheckResult
expected []struct {
lineNumber uint
}
}{
{
name: "no vulnerabilities",
args: args{
name: "vulnerabilities_test.go",
r: &checker.VulnerabilitiesData{
Vulnerabilities: []checker.Vulnerability{},
},
},
want: checker.CheckResult{
Score: 10,
},
},
{
name: "one vulnerability",
args: args{
name: "vulnerabilities_test.go",
r: &checker.VulnerabilitiesData{
Vulnerabilities: []checker.Vulnerability{
{
ID: "CVE-2019-1234",
},
},
},
},
want: checker.CheckResult{
Score: 9,
},
},
{
name: "one vulnerability",
args: args{
name: "vulnerabilities_test.go",
},
want: checker.CheckResult{
Score: -1,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
dl := scut.TestDetailLogger{}
res := Vulnerabilities(tt.args.name, &dl, tt.args.r)
if res.Score != tt.want.Score {
t.Errorf("Vulnerabilities() = %v, want %v", res.Score, tt.want.Score)
}
})
}
}

0 comments on commit 009aa85

Please sign in to comment.