Skip to content

Commit

Permalink
Merge branch 'main' into fix/benalvo/vorpal-for-arm
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvoBen authored Aug 29, 2024
2 parents 7d8a7b3 + 9aeea38 commit cccf1e4
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 50 deletions.
20 changes: 14 additions & 6 deletions internal/commands/.scripts/integration_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ if [ ! -s "$FAILED_TESTS_FILE" ]; then
# If the file is empty, all tests passed
echo "All tests passed."
rm -f "$FAILED_TESTS_FILE" test_output.log
exit 0
else
# If the file is not empty, rerun the failed tests
echo "Rerunning failed tests..."
Expand All @@ -56,7 +55,7 @@ else
go test \
-tags integration \
-v \
-timeout 210m \
-timeout 30m \
-coverpkg github.com/checkmarx/ast-cli/internal/commands,github.com/checkmarx/ast-cli/internal/services,github.com/checkmarx/ast-cli/internal/wrappers \
-coverprofile cover_rerun.out \
-run "^$testName$" \
Expand All @@ -75,11 +74,20 @@ else
# Step 6: Check if any tests failed again
if [ $rerun_status -eq 1 ]; then
echo "Some tests are still failing."
rm -f "$FAILED_TESTS_FILE" test_output.log
exit 1
else
echo "All failed tests passed on rerun."
rm -f "$FAILED_TESTS_FILE" test_output.log
exit 0
fi
fi

# Step 7: Run the cleandata package to delete projects
echo "Running cleandata to clean up projects..."
go test -v github.com/checkmarx/ast-cli/test/cleandata

# Step 8: Final cleanup and exit
rm -f "$FAILED_TESTS_FILE" test_output.log

if [ $status -ne 0 ] || [ $rerun_status -eq 1 ]; then
exit 1
else
exit 0
fi
51 changes: 51 additions & 0 deletions test/cleandata/clean-data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cleandata

import (
"bufio"
"fmt"
"log"
"os"
"testing"

"github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/checkmarx/ast-cli/internal/wrappers/configuration"
"github.com/spf13/viper"
)

const ProjectNameFile = "projectName.txt"

func DeleteProjectByName(projectName string) {
projectsWrapper := wrappers.NewHTTPProjectsWrapper(viper.GetString(params.ProjectsPathKey))
projectModel, _, err := projectsWrapper.GetByName(projectName)
if err == nil && projectModel != nil {
_, _ = projectsWrapper.Delete(projectModel.ID)
}
}

func TestDeleteProjectsFromFile(t *testing.T) {
configuration.LoadConfiguration()
projectNameFile := fmt.Sprint("../integration/", ProjectNameFile) // Replace with your actual file path

file, err := os.Open(projectNameFile)
if err != nil {
log.Printf("Failed to open project name file: %v", err)
}
defer func(file *os.File) {
if err := file.Close(); err != nil {
log.Printf("Failed to close file: %v", err)
}
}(file)

scanner := bufio.NewScanner(file)
for scanner.Scan() {
projectName := scanner.Text()
log.Printf("Attempting to delete project: %s", projectName)
DeleteProjectByName(projectName)
log.Printf("Project deleted: %s", projectName)
}

if err := scanner.Err(); err != nil {
log.Printf("Error reading project name file: %v", err)
}
}
9 changes: 5 additions & 4 deletions test/integration/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
package integration

import (
"github.com/checkmarx/ast-cli/internal/commands/util"
"github.com/checkmarx/ast-cli/internal/logger"
"os"
"strings"
"testing"

"github.com/checkmarx/ast-cli/internal/commands/util"
"github.com/checkmarx/ast-cli/internal/logger"

"github.com/checkmarx/ast-cli/internal/params"
"gotest.tools/assert"
)
Expand Down Expand Up @@ -118,7 +119,7 @@ func TestPRGitlabDecorationFailure(t *testing.T) {
}

func TestPRGithubDecoration_WhenScanIsRunning_ShouldAvoidPRDecorationCommand(t *testing.T) {
scanID, _ := createScanNoWait(t, Zip, Tags, GenerateRandomProjectNameForScan())
scanID, _ := createScanNoWait(t, Zip, Tags, getProjectNameForScanTests())
args := []string{
"utils",
"pr",
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestPRGithubDecoration_WhenScanIsRunning_ShouldAvoidPRDecorationCommand(t *
}

func TestPRGitlabDecoration_WhenScanIsRunning_ShouldAvoidPRDecorationCommand(t *testing.T) {
scanID, _ := createScanNoWait(t, Zip, Tags, GenerateRandomProjectNameForScan())
scanID, _ := createScanNoWait(t, Zip, Tags, getProjectNameForScanTests())
args := []string{
"utils",
"pr",
Expand Down
4 changes: 0 additions & 4 deletions test/integration/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func TestResultListJson(t *testing.T) {
assert.Assert(t, uint(len(result.Results)) == result.TotalCount, "Should have results")

assertResultFilesCreated(t)

deleteScanAndProject()
}

// assert all files were created
Expand Down Expand Up @@ -152,8 +150,6 @@ func TestResultListForGlReports(t *testing.T) {
assert.Assert(t, uint(len(result.Results)) == result.TotalCount, "Should have results")

assertGlResultFilesCreated(t)

deleteScanAndProject()
}

func assertGlResultFilesCreated(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions test/integration/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func getRootProject(t *testing.T) (string, string) {

rootProjectId, rootProjectName = createProject(t, Tags, Groups)

//--------------------Write project name to file to delete it later--------------------
_ = WriteProjectNameToFile(fmt.Sprint(getProjectNameForTest(), "_for_scan"))
_ = WriteProjectNameToFile(rootProjectName)
//-------------------------------------------------------------------------------------

return rootProjectId, rootProjectName
}

Expand Down
Loading

0 comments on commit cccf1e4

Please sign in to comment.