Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove from system sca json file when using scan create with scaResolver (AST-48074) #922

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ func runScaResolver(sourceDir, scaResolver, scaResolverParams, projectName strin
if err != nil {
return errors.Errorf("%s", err)
}
_ = os.Remove(scaFile.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check the results of this action, and log it
something like:
err = os.Remove(scaFile.Name())
if err != nil {
log.Printf("Failed to remove file %s: %v", scaFile.Name(), err)
} else {
log.Printf("Successfully removed file %s", scaFile.Name())
}

}
return nil
}
Expand Down
15 changes: 15 additions & 0 deletions internal/commands/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package commands

import (
"fmt"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -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")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a continuation of the previous comment
check the logs to see that file really deleted

Loading