diff --git a/checker/raw_result_test.go b/checker/raw_result_test.go index db43b4b5d90..a7cd962acbc 100644 --- a/checker/raw_result_test.go +++ b/checker/raw_result_test.go @@ -47,6 +47,7 @@ func TestFile_Location(t *testing.T) { t.Errorf("Expected *loc.Snippet to be 'some code', got %v", *loc.Snippet) } } + func TestPinningDependenciesData_GetStagedDependencies(t *testing.T) { t.Parallel() @@ -144,9 +145,10 @@ func TestPinningDependenciesData_GetStagedDependencies(t *testing.T) { expected: []Dependency{}, }, } - for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() result := tt.data.GetStagedDependencies(tt.useType) if len(result) != len(tt.expected) { t.Errorf("Expected %d dependencies, got %d", len(tt.expected), len(result)) diff --git a/checks/raw/csproj_parser.go b/checks/fileparser/csproj_parser.go similarity index 90% rename from checks/raw/csproj_parser.go rename to checks/fileparser/csproj_parser.go index 5432d118ac0..ca1fbb0fac2 100644 --- a/checks/raw/csproj_parser.go +++ b/checks/fileparser/csproj_parser.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package raw +package fileparser import ( "encoding/xml" @@ -28,12 +28,12 @@ type Project struct { PropertyGroups []PropertyGroup `xml:"PropertyGroup"` } -func isRestoreLockedModeEnabled(content []byte) (error, bool) { +func IsRestoreLockedModeEnabled(content []byte) (error, bool) { var project Project err := xml.Unmarshal(content, &project) if err != nil { - return errInvalidCsProjFile, false + return ErrInvalidCsProjFile, false } for _, propertyGroup := range project.PropertyGroups { diff --git a/checks/fileparser/errors.go b/checks/fileparser/errors.go index 88a6768f7be..e442e3edf1c 100644 --- a/checks/fileparser/errors.go +++ b/checks/fileparser/errors.go @@ -21,4 +21,5 @@ import ( var ( errInvalidGitHubWorkflow = errors.New("invalid GitHub workflow") errInternalFilenameMatch = errors.New("filename match error") + ErrInvalidCsProjFile = errors.New("error parsing csproj file") ) diff --git a/checks/raw/errors.go b/checks/raw/errors.go index a634e489326..23eb5aeb7eb 100644 --- a/checks/raw/errors.go +++ b/checks/raw/errors.go @@ -24,5 +24,4 @@ var ( errInvalidArgType = errors.New("invalid arg type") errInvalidArgLength = errors.New("invalid arg length") errInvalidGitHubWorkflow = errors.New("invalid GitHub workflow") - errInvalidCsProjFile = errors.New("error parsing csproj file") ) diff --git a/checks/raw/pinned_dependencies.go b/checks/raw/pinned_dependencies.go index 49900dbc585..e8c9274983b 100644 --- a/checks/raw/pinned_dependencies.go +++ b/checks/raw/pinned_dependencies.go @@ -122,7 +122,7 @@ func analyseCsprojLockedMode(path string, content []byte, args ...interface{}) ( panic(fmt.Sprintf("expected type []checker.Dependency, got %v", reflect.TypeOf(args[0]))) } - err, pinned := isRestoreLockedModeEnabled(content) + err, pinned := fileparser.IsRestoreLockedModeEnabled(content) if err != nil { return true, err } diff --git a/checks/raw/pinned_dependencies_test.go b/checks/raw/pinned_dependencies_test.go index e89b4360cc6..31f2a2ba946 100644 --- a/checks/raw/pinned_dependencies_test.go +++ b/checks/raw/pinned_dependencies_test.go @@ -2090,15 +2090,15 @@ func TestCsProjAnalysis(t *testing.T) { //nolint:govet tests := []struct { - warns int - err error - name string - filename string + warns int + expectError bool + name string + filename string }{ { - name: "empty file", - filename: "./testdata/dotnet-empty.csproj", - err: errInvalidCsProjFile, + name: "empty file", + filename: "./testdata/dotnet-empty.csproj", + expectError: true, }, { name: "locked mode enabled", @@ -2116,9 +2116,9 @@ func TestCsProjAnalysis(t *testing.T) { warns: 1, }, { - name: "invalid file", - filename: "./testdata/dotnet-invalid.csproj", - err: errInvalidCsProjFile, + name: "invalid file", + filename: "./testdata/dotnet-invalid.csproj", + expectError: true, }, } for _, tt := range tests { @@ -2139,8 +2139,8 @@ func TestCsProjAnalysis(t *testing.T) { var r []checker.Dependency _, err = analyseCsprojLockedMode(p, content, &r) - if !errCmp(err, tt.err) { - t.Error(cmp.Diff(err, tt.err, cmpopts.EquateErrors())) + if err != nil && !tt.expectError { + t.Errorf("unexpected error %e", err) } if err != nil {