mirror of
https://github.com/ossf/scorecard.git
synced 2024-11-05 05:17:00 +03:00
🌱 Unit test for dependency_update_tool
Unit tests for dependency_update_tool https://github.com/ossf/scorecard/issues/986
This commit is contained in:
parent
b4eec8ed94
commit
4c266d7192
@ -17,7 +17,10 @@ package raw
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
"github.com/ossf/scorecard/v4/checker"
|
||||
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
|
||||
)
|
||||
|
||||
func Test_checkDependencyFileExists(t *testing.T) {
|
||||
@ -122,3 +125,53 @@ func Test_checkDependencyFileExists(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDependencyUpdateTool tests the DependencyUpdateTool function.
|
||||
func TestDependencyUpdateTool(t *testing.T) {
|
||||
t.Parallel()
|
||||
//nolint
|
||||
tests := []struct {
|
||||
name string
|
||||
wantErr bool
|
||||
want int
|
||||
files []string
|
||||
}{
|
||||
{
|
||||
name: "dependency update tool",
|
||||
wantErr: false,
|
||||
want: 1,
|
||||
files: []string{
|
||||
".github/dependabot.yml",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo bar",
|
||||
wantErr: false,
|
||||
want: 0,
|
||||
files: []string{
|
||||
".github/foobar.yml",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
mockRepo := mockrepo.NewMockRepoClient(ctrl)
|
||||
mockRepo.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil)
|
||||
|
||||
got, err := DependencyUpdateTool(mockRepo)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("DependencyUpdateTool() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !tt.wantErr {
|
||||
if len(got.Tools) != tt.want {
|
||||
t.Errorf("DependencyUpdateTool() = %v, want %v", got.Tools, tt.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user