Skip to content

Commit

Permalink
🌱 Unit test for dependency_update_tool
Browse files Browse the repository at this point in the history
Unit tests for dependency_update_tool
 #986
  • Loading branch information
naveensrinivasan committed Jan 28, 2022
1 parent b4eec8e commit 4c266d7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions checks/raw/dependency_update_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
})
}
}

0 comments on commit 4c266d7

Please sign in to comment.