Skip to content

Commit

Permalink
changed fix func into a method
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Oct 19, 2023
1 parent 11e0dc9 commit 407ad4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packagehandlers/gradlepackagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (gph *GradlePackageHandler) updateDirectDependency(vulnDetails *utils.Vulne
isAnyDescriptorFileChanged := false
for _, descriptorFilePath := range descriptorFilesPaths {
var isFileChanged bool
isFileChanged, err = fixGradleVulnerabilityIfExists(descriptorFilePath, vulnDetails)
isFileChanged, err = gph.fixVulnerabilityIfExists(descriptorFilePath, vulnDetails)
if err != nil {
return
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func getDescriptorFilesPaths() (descriptorFilesPaths []string, err error) {
}

// Fixes all direct occurrences of the given vulnerability in the given descriptor file, if vulnerability occurs
func fixGradleVulnerabilityIfExists(descriptorFilePath string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) {
func (gph *GradlePackageHandler) fixVulnerabilityIfExists(descriptorFilePath string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) {
byteFileContent, err := os.ReadFile(descriptorFilePath)
if err != nil {
err = fmt.Errorf("couldn't read file '%s': %s", descriptorFilePath, err.Error())
Expand Down
6 changes: 4 additions & 2 deletions packagehandlers/packagehandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func TestGradleGetDescriptorFilesPaths(t *testing.T) {
assert.ElementsMatch(t, expectedResults, buildFilesPaths)
}

func TestFixGradleVulnerabilityIfExists(t *testing.T) {
func TestGradleFixVulnerabilityIfExists(t *testing.T) {
var testcases = []struct {
vulnerabilityDetails *utils.VulnerabilityDetails
}{
Expand Down Expand Up @@ -716,10 +716,12 @@ func TestFixGradleVulnerabilityIfExists(t *testing.T) {
descriptorFiles, err := getDescriptorFilesPaths()
assert.NoError(t, err)

gph := GradlePackageHandler{}

for _, descriptorFile := range descriptorFiles {
for _, testcase := range testcases {
var isFileChanged bool
isFileChanged, err = fixGradleVulnerabilityIfExists(descriptorFile, testcase.vulnerabilityDetails)
isFileChanged, err = gph.fixVulnerabilityIfExists(descriptorFile, testcase.vulnerabilityDetails)
assert.NoError(t, err)
assert.True(t, isFileChanged)
}
Expand Down

0 comments on commit 407ad4c

Please sign in to comment.