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 | Make integration tests run faster and improve stability #844

Merged
merged 28 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
- run: go version
- name: Go Build
run: go build -o ./bin/cx ./cmd
- name: Install gocovmerge
run: go install github.com/wadey/gocovmerge@latest
- name: Go Integration test
shell: bash
env:
Expand Down
73 changes: 65 additions & 8 deletions internal/commands/.scripts/integration_up.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Start the Squid proxy in a Docker container
docker run \
--name squid \
-d \
Expand All @@ -6,23 +7,79 @@ docker run \
-v $(pwd)/internal/commands/.scripts/squid/passwords:/etc/squid/passwords \
ubuntu/squid:5.2-22.04_beta

# Download and extract the ScaResolver tool
wget https://sca-downloads.s3.amazonaws.com/cli/latest/ScaResolver-linux64.tar.gz
tar -xzvf ScaResolver-linux64.tar.gz -C /tmp
rm -rf ScaResolver-linux64.tar.gz

# Step 1: Check if the failedTests file exists
FAILED_TESTS_FILE="failedTests"

# Step 2: Create the failedTests file
echo "Creating $FAILED_TESTS_FILE..."
touch "$FAILED_TESTS_FILE"

# Step 3: Run all tests and write failed test names to failedTests file
echo "Running all tests..."
go test \
-tags integration \
-v \
-timeout 210m \
-coverpkg github.com/checkmarx/ast-cli/internal/commands,github.com/checkmarx/ast-cli/internal/services,github.com/checkmarx/ast-cli/internal/wrappers \
-coverprofile cover.out \
github.com/checkmarx/ast-cli/test/integration
-tags integration \
-v \
-timeout 210m \
-coverpkg github.com/checkmarx/ast-cli/internal/commands,github.com/checkmarx/ast-cli/internal/services,github.com/checkmarx/ast-cli/internal/wrappers \
-coverprofile cover.out \
github.com/checkmarx/ast-cli/test/integration 2>&1 | tee test_output.log

# Generate the initial HTML coverage report
go tool cover -html=cover.out -o coverage.html

# Extract names of failed tests and save them in the failedTests file
grep -E "^--- FAIL: " test_output.log | awk '{print $3}' > "$FAILED_TESTS_FILE"

# Capture the exit status of the tests
status=$?
echo "status value after tests $status"
if [ $status -ne 0 ]; then
echo "Integration tests failed"
rm cover.out
fi

go tool cover -html=cover.out -o coverage.html
# Step 4: Check if failedTests file is empty
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..."
rerun_status=0
while IFS= read -r testName; do
go test \
-tags integration \
-v \
-timeout 210m \
-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$" \
github.com/checkmarx/ast-cli/test/integration || rerun_status=1
done < "$FAILED_TESTS_FILE"

# Step 5: Merge the original and rerun coverage profiles
if [ -f cover_rerun.out ]; then
echo "Merging coverage profiles..."
gocovmerge cover.out cover_rerun.out > merged_coverage.out
mv merged_coverage.out cover.out
go tool cover -html=cover.out -o coverage.html
rm -f cover_rerun.out
fi

# 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
1 change: 0 additions & 1 deletion test/integration/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func assertResultFilesCreated(t *testing.T) {
}

func TestResultListForGlReports(t *testing.T) {

assertRequiredParameter(t, "Please provide a scan ID", "results", "show")

scanID, _ := getRootScan(t)
Expand Down
Loading
Loading