mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-17 11:57:12 +03:00
🌱 Unit tests dependency_update_tool
Unit tests dependency_update_tool https://github.com/ossf/scorecard/issues/986 Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
This commit is contained in:
parent
b6cba86f72
commit
d4d81a01df
180
checks/evaluation/dependency_update_tool_test.go
Normal file
180
checks/evaluation/dependency_update_tool_test.go
Normal file
@ -0,0 +1,180 @@
|
||||
// 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"
|
||||
sce "github.com/ossf/scorecard/v4/errors"
|
||||
scut "github.com/ossf/scorecard/v4/utests"
|
||||
)
|
||||
|
||||
func TestDependencyUpdateTool(t *testing.T) {
|
||||
t.Parallel()
|
||||
//nolint
|
||||
type args struct {
|
||||
name string
|
||||
dl checker.DetailLogger
|
||||
r *checker.DependencyUpdateToolData
|
||||
}
|
||||
//nolint
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want checker.CheckResult
|
||||
err bool
|
||||
expected scut.TestReturn
|
||||
}{
|
||||
{
|
||||
name: "DependencyUpdateTool",
|
||||
args: args{
|
||||
name: "DependencyUpdateTool",
|
||||
dl: &scut.TestDetailLogger{},
|
||||
r: &checker.DependencyUpdateToolData{
|
||||
Tools: []checker.Tool{
|
||||
{
|
||||
Name: "DependencyUpdateTool",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: checker.CheckResult{
|
||||
Score: -1,
|
||||
},
|
||||
err: false,
|
||||
expected: scut.TestReturn{
|
||||
Error: sce.ErrScorecardInternal,
|
||||
Score: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty tool list",
|
||||
args: args{
|
||||
name: "DependencyUpdateTool",
|
||||
dl: &scut.TestDetailLogger{},
|
||||
r: &checker.DependencyUpdateToolData{
|
||||
Tools: []checker.Tool{},
|
||||
},
|
||||
},
|
||||
want: checker.CheckResult{
|
||||
Score: 0,
|
||||
Error2: nil,
|
||||
},
|
||||
err: false,
|
||||
expected: scut.TestReturn{
|
||||
Score: 0,
|
||||
NumberOfWarn: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Valid tool",
|
||||
args: args{
|
||||
name: "DependencyUpdateTool",
|
||||
dl: &scut.TestDetailLogger{},
|
||||
r: &checker.DependencyUpdateToolData{
|
||||
Tools: []checker.Tool{
|
||||
{
|
||||
Name: "DependencyUpdateTool",
|
||||
ConfigFiles: []checker.File{
|
||||
{
|
||||
Path: "/etc/dependency-update-tool.conf",
|
||||
Snippet: `
|
||||
[dependency-update-tool]
|
||||
enabled = true
|
||||
`,
|
||||
Offset: 0,
|
||||
Type: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: checker.CheckResult{
|
||||
Score: 10,
|
||||
Error2: nil,
|
||||
},
|
||||
expected: scut.TestReturn{
|
||||
Error: nil,
|
||||
Score: 10,
|
||||
NumberOfInfo: 1,
|
||||
},
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "more than one tool in the list",
|
||||
args: args{
|
||||
name: "DependencyUpdateTool",
|
||||
dl: &scut.TestDetailLogger{},
|
||||
r: &checker.DependencyUpdateToolData{
|
||||
Tools: []checker.Tool{
|
||||
{
|
||||
Name: "DependencyUpdateTool",
|
||||
},
|
||||
{
|
||||
Name: "DependencyUpdateTool",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: checker.CheckResult{
|
||||
Score: -1,
|
||||
Error2: nil,
|
||||
},
|
||||
expected: scut.TestReturn{
|
||||
Error: sce.ErrScorecardInternal,
|
||||
Score: -1,
|
||||
},
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "Nil r",
|
||||
args: args{
|
||||
name: "nil r",
|
||||
dl: &scut.TestDetailLogger{},
|
||||
},
|
||||
want: checker.CheckResult{
|
||||
Score: -1,
|
||||
Error2: nil,
|
||||
},
|
||||
expected: scut.TestReturn{
|
||||
Error: sce.ErrScorecardInternal,
|
||||
Score: -1,
|
||||
},
|
||||
err: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dl := scut.TestDetailLogger{}
|
||||
got := DependencyUpdateTool(tt.args.name, &dl, tt.args.r)
|
||||
if tt.want.Score != got.Score {
|
||||
t.Errorf("DependencyUpdateTool() got Score = %v, want %v for %v", got.Score, tt.want.Score, tt.name)
|
||||
}
|
||||
if tt.err && got.Error2 == nil {
|
||||
t.Errorf("DependencyUpdateTool() error = %v, want %v for %v", got.Error2, tt.want.Error2, tt.name)
|
||||
return
|
||||
}
|
||||
|
||||
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &got, &dl) {
|
||||
t.Fatalf(tt.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -124,6 +124,7 @@ func ValidateTestReturn(t *testing.T, name string, expected *TestReturn,
|
||||
}
|
||||
if !cmp.Equal(*expected, *actualTestReturn, cmp.Comparer(errCmp)) {
|
||||
log.Println(name+":", cmp.Diff(*expected, *actualTestReturn))
|
||||
t.Logf(name+":", cmp.Diff(*expected, *actualTestReturn))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
Loading…
Reference in New Issue
Block a user