From 407ad4ca6a189f643c6223d69fffcd5f762bb328 Mon Sep 17 00:00:00 2001 From: Eran Turgeman Date: Thu, 19 Oct 2023 11:06:15 +0300 Subject: [PATCH] changed fix func into a method --- packagehandlers/gradlepackagehandler.go | 4 ++-- packagehandlers/packagehandlers_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packagehandlers/gradlepackagehandler.go b/packagehandlers/gradlepackagehandler.go index 9f0bcd89b..a33d0806a 100644 --- a/packagehandlers/gradlepackagehandler.go +++ b/packagehandlers/gradlepackagehandler.go @@ -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 } @@ -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()) diff --git a/packagehandlers/packagehandlers_test.go b/packagehandlers/packagehandlers_test.go index 1d37b8828..59383f15a 100644 --- a/packagehandlers/packagehandlers_test.go +++ b/packagehandlers/packagehandlers_test.go @@ -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 }{ @@ -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) }