Skip to content

Commit 24f6e6a

Browse files
committed
Enhance integration tests with matrix strategy and improved coverage reporting
1 parent 828a903 commit 24f6e6a

File tree

1 file changed

+133
-9
lines changed

1 file changed

+133
-9
lines changed

.github/workflows/ci-tests.yml

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ jobs:
3333
fi
3434
integration-tests:
3535
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
test-group:
40+
- name: "scan-create"
41+
pattern: "^(TestScan|TestCreate|TestCancel|TestBranch|TestBroken|TestIncremental)"
42+
- name: "container"
43+
pattern: "^TestContainer"
44+
- name: "results"
45+
pattern: "^(TestResults|TestResult_)"
46+
- name: "auth-config"
47+
pattern: "^(TestAuth|TestLoad|TestSet|TestRoot|TestTenant|TestTelemetry)"
48+
- name: "pr-decoration"
49+
pattern: "^TestPR"
50+
- name: "git-providers"
51+
pattern: "^(TestAzure|TestBitbucket|TestGit)"
52+
- name: "realtime-engines"
53+
pattern: "^(TestIac|TestOss|TestSca|TestSecrets|TestExecute|TestASCA)"
54+
- name: "other"
55+
pattern: "^(TestCode|TestImport|TestProject|TestChat|TestPre|TestHooks|TestKics|TestRun|Test_)"
3656
steps:
3757
- name: Checkout the repository
3858
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 #v4.0.0
@@ -49,7 +69,21 @@ jobs:
4969
run: |
5070
pip install pre-commit
5171
pre-commit install
52-
- name: Go Integration test
72+
- name: Start Squid Proxy
73+
run: |
74+
docker run \
75+
--name squid \
76+
-d \
77+
-p 3128:3128 \
78+
-v $(pwd)/internal/commands/.scripts/squid/squid.conf:/etc/squid/squid.conf \
79+
-v $(pwd)/internal/commands/.scripts/squid/passwords:/etc/squid/passwords \
80+
ubuntu/squid:5.2-22.04_beta
81+
- name: Download ScaResolver
82+
run: |
83+
wget https://sca-downloads.s3.amazonaws.com/cli/latest/ScaResolver-linux64.tar.gz
84+
tar -xzvf ScaResolver-linux64.tar.gz -C /tmp
85+
rm -rf ScaResolver-linux64.tar.gz
86+
- name: Run Integration Tests - ${{ matrix.test-group.name }}
5387
shell: bash
5488
env:
5589
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
@@ -95,27 +129,117 @@ jobs:
95129
PR_BITBUCKET_REPO_NAME: "cliIntegrationTest"
96130
PR_BITBUCKET_ID: 1
97131
run: |
98-
sudo chmod +x ./internal/commands/.scripts/integration_up.sh ./internal/commands/.scripts/integration_down.sh
99-
./internal/commands/.scripts/integration_up.sh
100-
./internal/commands/.scripts/integration_down.sh
132+
echo "Running test group: ${{ matrix.test-group.name }}"
133+
echo "Test pattern: ${{ matrix.test-group.pattern }}"
134+
135+
go test \
136+
-tags integration \
137+
-v \
138+
-timeout 60m \
139+
-run "${{ matrix.test-group.pattern }}" \
140+
-coverpkg github.com/checkmarx/ast-cli/internal/commands,github.com/checkmarx/ast-cli/internal/services,github.com/checkmarx/ast-cli/internal/wrappers \
141+
-coverprofile cover-${{ matrix.test-group.name }}.out \
142+
github.com/checkmarx/ast-cli/test/integration 2>&1 | tee test_output.log
143+
144+
TEST_EXIT_CODE=${PIPESTATUS[0]}
145+
146+
# Check for failed tests
147+
if grep -q "^--- FAIL:" test_output.log; then
148+
echo "Some tests failed, attempting retry..."
149+
grep -E "^--- FAIL: " test_output.log | awk '{print $3}' > failedTests
150+
151+
while IFS= read -r testName; do
152+
echo "Retrying: $testName"
153+
go test \
154+
-tags integration \
155+
-v \
156+
-timeout 30m \
157+
-run "^$testName$" \
158+
-coverpkg github.com/checkmarx/ast-cli/internal/commands,github.com/checkmarx/ast-cli/internal/services,github.com/checkmarx/ast-cli/internal/wrappers \
159+
-coverprofile cover_rerun.out \
160+
github.com/checkmarx/ast-cli/test/integration || TEST_EXIT_CODE=1
161+
162+
if [ -f cover_rerun.out ]; then
163+
gocovmerge cover-${{ matrix.test-group.name }}.out cover_rerun.out > merged.out
164+
mv merged.out cover-${{ matrix.test-group.name }}.out
165+
rm -f cover_rerun.out
166+
fi
167+
done < failedTests
168+
fi
169+
170+
exit $TEST_EXIT_CODE
171+
172+
- name: Cleanup projects
173+
if: always()
174+
shell: bash
175+
env:
176+
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
177+
CX_APIKEY: ${{ secrets.CX_APIKEY }}
178+
run: |
179+
if [ -f projectName.txt ]; then
180+
go test -v github.com/checkmarx/ast-cli/test/cleandata || true
181+
fi
182+
183+
- name: Stop Squid Proxy
184+
if: always()
185+
run: docker rm -f squid || true
186+
187+
- name: Upload coverage artifact
188+
if: always()
189+
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4
190+
with:
191+
name: coverage-${{ matrix.test-group.name }}
192+
path: cover-${{ matrix.test-group.name }}.out
193+
retention-days: 1
194+
195+
merge-coverage:
196+
runs-on: ubuntu-latest
197+
needs: integration-tests
198+
if: always()
199+
steps:
200+
- name: Checkout the repository
201+
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 #v4.0.0
202+
- name: Set up Go version
203+
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 #v4
204+
with:
205+
go-version-file: go.mod
206+
- name: Install gocovmerge
207+
run: go install github.com/wadey/gocovmerge@latest
208+
209+
- name: Download all coverage artifacts
210+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 #v4
211+
with:
212+
pattern: coverage-*
213+
merge-multiple: true
214+
path: ./coverage-reports
215+
216+
- name: Merge coverage reports
217+
run: |
218+
echo "Coverage files found:"
219+
ls -la ./coverage-reports/
220+
221+
gocovmerge ./coverage-reports/cover-*.out > cover.out
222+
go tool cover -html=cover.out -o coverage.html
223+
224+
echo "Merged coverage report generated"
101225
102-
- name: Coverage report
226+
- name: Upload merged coverage report
103227
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4
104228
with:
105-
name: ${{ runner.os }}-coverage-latest
229+
name: ${{ runner.os }}-coverage-merged
106230
path: coverage.html
107231

108-
- name: Check if total coverage is greater then 75
232+
- name: Check if total coverage is greater than 75
109233
shell: bash
110234
run: |
111235
CODE_COV=$(go tool cover -func cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
112236
EXPECTED_CODE_COV=75
113237
var=$(awk 'BEGIN{ print "'$CODE_COV'"<"'$EXPECTED_CODE_COV'" }')
114238
if [ "$var" -eq 1 ];then
115-
echo "Your code coverage is too low. Coverage precentage is: $CODE_COV"
239+
echo "Your code coverage is too low. Coverage percentage is: $CODE_COV"
116240
exit 1
117241
else
118-
echo "Your code coverage test passed! Coverage precentage is: $CODE_COV"
242+
echo "Your code coverage test passed! Coverage percentage is: $CODE_COV"
119243
exit 0
120244
fi
121245
lint:

0 commit comments

Comments
 (0)