Skip to content

Commit

Permalink
move csproj to fileparser
Browse files Browse the repository at this point in the history
Signed-off-by: balteraivshay <[email protected]>
  • Loading branch information
balteravishay committed Sep 18, 2024
1 parent ca23510 commit c50d2b8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion checker/raw_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions checks/fileparser/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
1 change: 0 additions & 1 deletion checks/raw/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
2 changes: 1 addition & 1 deletion checks/raw/pinned_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions checks/raw/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit c50d2b8

Please sign in to comment.