Skip to content

Commit c983220

Browse files
committed
[PLUTO-1412] test init
1 parent c584641 commit c983220

File tree

7 files changed

+189
-3
lines changed

7 files changed

+189
-3
lines changed

.github/workflows/it-test.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ jobs:
4848
if: matrix.os != 'windows-latest'
4949
run: chmod +x cli-v2
5050

51+
52+
- name: Run init command tests
53+
if: matrix.os != 'windows-latest'
54+
id: run_init_tests
55+
continue-on-error: true
56+
shell: bash
57+
env:
58+
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
59+
run: |
60+
# Make the script executable
61+
chmod +x integration-tests/run.sh
62+
63+
# Run the init command tests
64+
echo "Running init command integration tests..."
65+
./integration-tests/run.sh || {
66+
echo "❌ Init command tests failed"
67+
echo "::error::Init command tests failed. Please check the logs above for details."
68+
exit 1
69+
}
70+
echo "✅ Init command tests passed successfully!"
71+
5172
- name: Run tool tests
5273
if: matrix.os != 'windows-latest'
5374
id: run_tests
@@ -84,7 +105,7 @@ jobs:
84105
fi
85106
86107
- name: Check test results
87-
if: steps.run_tests.outcome == 'failure'
108+
if: steps.run_tests.outcome == 'failure' || steps.run_init_tests.outcome == 'failure'
88109
run: |
89-
echo "Job failed because some tool tests failed. Please check the logs above for details."
110+
echo "Job failed because some tests failed. Please check the logs above for details."
90111
exit 1

cmd/init.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ func createLizardConfigFile(toolsConfigDir string, patternConfiguration []domain
541541
var patterns []domain.PatternDefinition
542542

543543
if len(patternConfiguration) == 0 {
544-
fmt.Println("Using default Lizard configuration")
545544
var err error
546545
patterns, err = tools.FetchDefaultEnabledPatterns(Lizard)
547546
if err != nil {
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
runtimes:
2+
3+
4+
5+
tools:
6+
7+
8+
9+
10+
11+
12+
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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
echo "=== Expected file content ==="
25+
cat "$file"
26+
echo "=== Actual file content ==="
27+
cat "$actual_dir/$filename"
28+
echo "=== Diff output ==="
29+
diff "$file" "$actual_dir/$filename" || true
30+
echo "==================="
31+
exit 1
32+
fi
33+
fi
34+
done
35+
36+
# Recursively compare subdirectories
37+
for dir in "$expected_dir"/*/; do
38+
if [ -d "$dir" ]; then
39+
dirname=$(basename "$dir")
40+
# Skip logs directory
41+
if [ "$dirname" = "logs" ]; then
42+
continue
43+
fi
44+
if [ ! -d "$actual_dir/$dirname" ]; then
45+
echo "❌ Directory $label/$dirname does not exist in actual output"
46+
exit 1
47+
fi
48+
compare_files "$dir" "$actual_dir/$dirname" "$label/$dirname"
49+
fi
50+
done
51+
}
52+
53+
run_init_test() {
54+
local test_dir="$1"
55+
local test_name="$2"
56+
local use_token="$3"
57+
58+
echo "Running test: $test_name"
59+
cd "$test_dir" || exit 1
60+
61+
# Clean up any existing .codacy directory
62+
rm -rf .codacy
63+
64+
# Run analysis with appropriate command
65+
if [ "$use_token" = "true" ]; then
66+
if [ -z "$CODACY_API_TOKEN" ]; then
67+
echo "❌ Skipping token-based test: CODACY_API_TOKEN not set"
68+
return 0
69+
fi
70+
"$CLI_PATH" init --api-token "$CODACY_API_TOKEN" --organization troubleshoot-codacy-dev --provider gh --repository codacy-cli-test
71+
else
72+
"$CLI_PATH" init
73+
fi
74+
75+
# Compare all files from expected directory
76+
compare_files "expected" ".codacy" "Test $test_name"
77+
78+
echo "✅ Test $test_name completed successfully"
79+
echo "----------------------------------------"
80+
}
81+
82+
# Run both tests
83+
echo "Starting integration tests..."
84+
echo "----------------------------------------"
85+
86+
# Test 1: Init without token
87+
run_init_test "integration-tests/init-without-token" "init-without-token" "false"
88+
89+
# Test 2: Init with token
90+
run_init_test "integration-tests/init-with-token" "init-with-token" "true"
91+
92+
echo "All tests completed successfully! 🎉"
93+

0 commit comments

Comments
 (0)