Skip to content

Commit fe7fb4b

Browse files
committed
[PLUTO-1412] test init
1 parent 8062f87 commit fe7fb4b

File tree

7 files changed

+184
-4
lines changed

7 files changed

+184
-4
lines changed

.codacy/cli-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mode: local

.github/workflows/it-test.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-latest, macos-latest] # [windows-latest] removed for now
14+
os: [ubuntu-latest, macos-latest, windows-latest]
1515
fail-fast: false
1616
steps:
1717
- name: Checkout code
@@ -46,7 +46,6 @@ jobs:
4646
if: matrix.os != 'windows-latest'
4747
run: chmod +x cli-v2
4848

49-
5049
- name: Run tool tests
5150
if: matrix.os != 'windows-latest'
5251
id: run_tests
@@ -82,8 +81,28 @@ jobs:
8281
echo "✅ All tool tests passed successfully!"
8382
fi
8483
84+
- name: Run init command tests
85+
if: matrix.os != 'windows-latest'
86+
id: run_init_tests
87+
continue-on-error: true
88+
shell: bash
89+
env:
90+
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
91+
run: |
92+
# Make the script executable
93+
chmod +x integration-tests/run.sh
94+
95+
# Run the init command tests
96+
echo "Running init command integration tests..."
97+
./integration-tests/run.sh || {
98+
echo "❌ Init command tests failed"
99+
echo "::error::Init command tests failed. Please check the logs above for details."
100+
exit 1
101+
}
102+
echo "✅ Init command tests passed successfully!"
103+
85104
- name: Check test results
86-
if: steps.run_tests.outcome == 'failure'
105+
if: steps.run_tests.outcome == 'failure' || steps.run_init_tests.outcome == 'failure'
87106
run: |
88-
echo "Job failed because some tool tests failed. Please check the logs above for details."
107+
echo "Job failed because some tests failed. Please check the logs above for details."
89108
exit 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtimes:
2+
3+
4+
tools:
5+
6+
7+
8+
9+
10+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mode: local
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
runtimes:
2+
3+
4+
5+
tools:
6+
7+
8+
9+
10+
11+
12+
13+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
patterns:
2+
Lizard_ccn-medium:
3+
category: Complexity
4+
description: Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 8.
5+
explanation: |-
6+
# Medium Cyclomatic Complexity control
7+
8+
Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Medium issue. The default threshold is 7.
9+
id: Lizard_ccn-medium
10+
level: Warning
11+
severityLevel: Warning
12+
threshold: 8
13+
timeToFix: 5
14+
title: Medium Cyclomatic Complexity control
15+
Lizard_file-nloc-medium:
16+
category: Complexity
17+
description: Check the number of lines of code (without comments) in a file. If the threshold is not met, raise a Medium issue. The default threshold is 500.
18+
explanation: ""
19+
id: Lizard_file-nloc-medium
20+
level: Warning
21+
severityLevel: Warning
22+
threshold: 500
23+
timeToFix: 5
24+
title: Medium File NLOC control - Number of Lines of Code (without comments)
25+
Lizard_nloc-medium:
26+
category: Complexity
27+
description: Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
28+
explanation: |-
29+
# Medium NLOC control - Number of Lines of Code (without comments)
30+
31+
Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
32+
id: Lizard_nloc-medium
33+
level: Warning
34+
severityLevel: Warning
35+
threshold: 50
36+
timeToFix: 5
37+
title: Medium NLOC control - Number of Lines of Code (without comments)
38+
Lizard_parameter-count-medium:
39+
category: Complexity
40+
description: Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 8.
41+
explanation: |-
42+
# Medium Parameter count control
43+
44+
Check the number of parameters sent to a function. If the threshold is not met, raise a Medium issue. The default threshold is 5.
45+
id: Lizard_parameter-count-medium
46+
level: Warning
47+
severityLevel: Warning
48+
threshold: 8
49+
timeToFix: 5
50+
title: Medium Parameter count control

integration-tests/run.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CLI_PATH="$(pwd)/cli-v2"
5+
6+
# Check if API token is provided for token-based test
7+
if [ -z "$CODACY_API_TOKEN" ]; then
8+
echo "Warning: CODACY_API_TOKEN environment variable is not set. Token-based test will be skipped."
9+
fi
10+
11+
compare_files() {
12+
local expected_dir="$1"
13+
local actual_dir="$2"
14+
local label="$3"
15+
16+
# Compare all files in the current directory
17+
for file in "$expected_dir"/*; do
18+
if [ -f "$file" ]; then
19+
filename=$(basename "$file")
20+
if diff "$file" "$actual_dir/$filename" >/dev/null 2>&1; then
21+
echo "$label/$filename matches expected"
22+
else
23+
echo "$label/$filename does not match expected"
24+
exit 1
25+
fi
26+
fi
27+
done
28+
29+
# Recursively compare subdirectories
30+
for dir in "$expected_dir"/*/; do
31+
if [ -d "$dir" ]; then
32+
dirname=$(basename "$dir")
33+
# Skip logs directory
34+
if [ "$dirname" = "logs" ]; then
35+
continue
36+
fi
37+
if [ ! -d "$actual_dir/$dirname" ]; then
38+
echo "❌ Directory $label/$dirname does not exist in actual output"
39+
exit 1
40+
fi
41+
compare_files "$dir" "$actual_dir/$dirname" "$label/$dirname"
42+
fi
43+
done
44+
}
45+
46+
run_init_test() {
47+
local test_dir="$1"
48+
local test_name="$2"
49+
local use_token="$3"
50+
51+
echo "Running test: $test_name"
52+
cd "$test_dir" || exit 1
53+
54+
# Clean up any existing .codacy directory
55+
rm -rf .codacy
56+
57+
# Run analysis with appropriate command
58+
if [ "$use_token" = "true" ]; then
59+
if [ -z "$CODACY_API_TOKEN" ]; then
60+
echo "❌ Skipping token-based test: CODACY_API_TOKEN not set"
61+
return 0
62+
fi
63+
"$CLI_PATH" init --api-token "$CODACY_API_TOKEN" --organization troubleshoot-codacy-dev --provider gh --repository codacy-cli-test
64+
else
65+
"$CLI_PATH" init
66+
fi
67+
68+
# Compare all files from expected directory
69+
compare_files "expected" ".codacy" "Test $test_name"
70+
71+
echo "✅ Test $test_name completed successfully"
72+
echo "----------------------------------------"
73+
}
74+
75+
# Run both tests
76+
echo "Starting integration tests..."
77+
echo "----------------------------------------"
78+
79+
# Test 1: Init without token
80+
run_init_test "integration-tests/init-without-token" "init-without-token" "false"
81+
82+
# Test 2: Init with token
83+
run_init_test "integration-tests/init-with-token" "init-with-token" "true"
84+
85+
echo "All tests completed successfully! 🎉"
86+

0 commit comments

Comments
 (0)