-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests dependency_update_tool #986 Signed-off-by: naveen <[email protected]>
- Loading branch information
1 parent
b6cba86
commit d4d81a0
Showing
2 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters