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

CLI | Improve stability of integration tests (AST-64107) #851

Merged
merged 40 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ff7d674
optimize test run time
BenAlvo1 Aug 21, 2024
cb72cfd
optimize test run time
BenAlvo1 Aug 22, 2024
839497b
failed the job if some test failed
BenAlvo1 Aug 22, 2024
972b05e
revert parallel
BenAlvo1 Aug 22, 2024
5ebd2a7
try go test sum
BenAlvo1 Aug 22, 2024
7d91240
revert try go test sum
BenAlvo1 Aug 22, 2024
c79ba82
try go test sum
BenAlvo1 Aug 22, 2024
4e0e5d4
try go test sum
BenAlvo1 Aug 22, 2024
1cbcd04
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 22, 2024
d7b4ebd
remove scs score card test
BenAlvo1 Aug 25, 2024
eb0bed0
remove scs score card test
BenAlvo1 Aug 25, 2024
d346bae
set global timeout
BenAlvo1 Aug 25, 2024
b1265eb
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 25, 2024
27ed70b
set global timeout
BenAlvo1 Aug 25, 2024
2a0d02a
Revert TestCancelscan test
BenAlvo1 Aug 26, 2024
7662e25
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 26, 2024
6f82c74
Update integration_up.sh
AlvoBen Aug 26, 2024
77d6c19
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 26, 2024
560dfb9
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 27, 2024
6de1a18
try implement re run tests mechanism
BenAlvo1 Aug 27, 2024
3b3f86b
try implement re run tests mechanism
BenAlvo1 Aug 27, 2024
e54ff25
try implement re run tests mechanism
BenAlvo1 Aug 27, 2024
c698aa9
try implement re run tests mechanism
BenAlvo1 Aug 27, 2024
76c8f16
try implement re run tests mechanism
BenAlvo1 Aug 27, 2024
257c869
update integration_up.sh
BenAlvo1 Aug 27, 2024
e5224ed
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 27, 2024
bf89a68
fix coverage
BenAlvo1 Aug 27, 2024
7e1b2ff
merge coverages
BenAlvo1 Aug 27, 2024
14a097c
make test independent
BenAlvo1 Aug 28, 2024
be0abcd
Merge branch 'main' into benalvo/optimize-tests-time
AlvoBen Aug 28, 2024
1aff8de
make test independent
BenAlvo1 Aug 28, 2024
56f3cfc
make test independent
BenAlvo1 Aug 28, 2024
1a2279c
add ckean data flow
BenAlvo1 Aug 28, 2024
069d8b2
add ckean data flow
BenAlvo1 Aug 28, 2024
c2c0ef0
change rerun timeout to 60m
BenAlvo1 Aug 28, 2024
025d7e3
change rerun timeout to 60m
BenAlvo1 Aug 28, 2024
3a1baab
change rerun timeout to 60m
BenAlvo1 Aug 28, 2024
d6766ae
fix clean data
BenAlvo1 Aug 28, 2024
6abb12a
fix clean data
BenAlvo1 Aug 28, 2024
3808b5a
fix clean data
BenAlvo1 Aug 28, 2024
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
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
Loading