From db5452fb55c1eb401ba1f7c78b39582a496ca8a9 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Thu, 31 Oct 2024 14:34:11 +0200 Subject: [PATCH] Remove from system sca json file when using scan create with scaResolver --- internal/commands/scan.go | 1 + internal/commands/scan_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index f7c602d8d..598bee3bf 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -1356,6 +1356,7 @@ func runScaResolver(sourceDir, scaResolver, scaResolverParams, projectName strin if err != nil { return errors.Errorf("%s", err) } + _ = os.Remove(scaFile.Name()) } return nil } diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 536447c36..a841abcb3 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -4,6 +4,7 @@ package commands import ( "fmt" + "os" "reflect" "strings" "testing" @@ -1187,3 +1188,17 @@ func TestValidateContainerImageFormat(t *testing.T) { }) } } + +func TestRunScaResolverFileCleanup(t *testing.T) { + sourceDir := "/mock/sourceDir" + scaResolver := "/bin/echo" + scaResolverParams := "" + projectName := "testProject" + + err := runScaResolver(sourceDir, scaResolver, scaResolverParams, projectName) + + assert.NilError(t, err) + + _, err = os.Stat(scaResolverResultsFile) + assert.Assert(t, os.IsNotExist(err), "Expected temp file to be deleted, but it exists") +}