Skip to content

Commit 5c25c52

Browse files
GHA-132 Add tests for update-rule-metadata (#59)
1 parent faf0133 commit 5c25c52

1 file changed

Lines changed: 193 additions & 40 deletions

File tree

.github/workflows/test-update-rule-metadata.yml

Lines changed: 193 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
validation-tests:
19-
name: Test Input Validation
18+
input-parameter-tests:
19+
name: Test Input Parameters
2020
runs-on: ubuntu-latest
2121

2222
steps:
@@ -25,54 +25,109 @@ jobs:
2525

2626
- name: Test Default Inputs
2727
id: test-default
28-
run: |
29-
echo "Testing action with default inputs (no explicit parameters)"
30-
echo "Expected behavior: Action will attempt to run but likely fail due to missing vault access"
31-
echo "This validates that the action accepts default input values"
28+
uses: ./update-rule-metadata
29+
continue-on-error: true
3230

3331
- name: Test Custom Rule API Version
3432
id: test-rule-api-version
35-
run: |
36-
echo "Testing with custom rule-api-version parameter"
37-
echo "This validates that the action accepts custom rule-api version"
33+
uses: ./update-rule-metadata
34+
with:
35+
rule-api-version: '2.16.0.5000'
36+
continue-on-error: true
3837

3938
- name: Test Custom Sonarpedia Files
4039
id: test-sonarpedia-files
41-
run: |
42-
echo "Testing with custom sonarpedia-files parameter"
43-
echo "This validates that the action accepts comma-separated file list"
40+
uses: ./update-rule-metadata
41+
with:
42+
sonarpedia-files: 'test/sonarpedia.json,another/sonarpedia.json'
43+
continue-on-error: true
4444

45-
- name: Test Custom Branch
46-
id: test-branch
47-
run: |
48-
echo "Testing with custom branch parameter"
49-
echo "This validates that the action accepts custom branch parameter"
45+
- name: Test Custom Branch (master)
46+
id: test-branch-master
47+
uses: ./update-rule-metadata
48+
with:
49+
branch: 'master'
50+
continue-on-error: true
51+
52+
- name: Test Custom Branch (current)
53+
id: test-branch-current
54+
uses: ./update-rule-metadata
55+
with:
56+
branch: ${{ github.ref_name }}
57+
continue-on-error: true
5058

5159
- name: Test All Optional Parameters
5260
id: test-all-params
61+
uses: ./update-rule-metadata
62+
with:
63+
rule-api-version: '2.16.0.5000'
64+
sonarpedia-files: 'test/sonarpedia.json'
65+
branch: ${{ github.ref_name }}
66+
continue-on-error: true
67+
68+
- name: Verify Parameter Tests
5369
run: |
54-
echo "Testing with all optional parameters provided"
55-
echo "This validates that the action accepts all input combinations"
70+
echo "Input parameter test results:"
71+
echo "Default inputs test outcome: ${{ steps.test-default.outcome }}"
72+
echo "Custom rule-api-version test outcome: ${{ steps.test-rule-api-version.outcome }}"
73+
echo "Custom sonarpedia-files test outcome: ${{ steps.test-sonarpedia-files.outcome }}"
74+
echo "Custom branch (master) test outcome: ${{ steps.test-branch-master.outcome }}"
75+
echo "Custom branch (current) test outcome: ${{ steps.test-branch-current.outcome }}"
76+
echo "All parameters test outcome: ${{ steps.test-all-params.outcome }}"
77+
78+
# All tests are expected to fail due to missing vault access
79+
# We're testing that the parameters are accepted and don't cause syntax errors
80+
echo "✓ All parameter tests completed without syntax errors"
81+
echo "✓ Action accepts all valid input parameter combinations"
82+
83+
branch-parameter-tests:
84+
name: Test Branch Parameter Structure
85+
runs-on: ubuntu-latest
86+
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
5690

57-
- name: Summary of Validation Tests
91+
- name: Test Branch Parameter Structure
5892
run: |
59-
echo "================================"
60-
echo "Validation Test Results Summary:"
61-
echo "================================"
62-
echo "✓ Default inputs: Validated"
63-
echo "✓ Custom rule-api-version: Validated"
64-
echo "✓ Custom sonarpedia-files: Validated"
65-
echo "✓ Custom branch: Validated"
66-
echo "✓ All optional parameters: Validated"
67-
echo "================================"
68-
echo ""
69-
echo "Note: Full integration tests require:"
70-
echo " - Vault access for Artifactory credentials"
71-
echo " - Repository with sonarpedia.json files"
72-
echo " - Write permissions for creating pull requests"
93+
echo "Testing branch parameter structure..."
94+
95+
# Test that the action file has the branch input defined
96+
if grep -q "branch:" update-rule-metadata/action.yml; then
97+
echo "✓ branch input found in action.yml"
98+
else
99+
echo "✗ branch input not found in action.yml"
100+
exit 1
101+
fi
102+
103+
# Test that the branch input has a default value
104+
if grep -A3 "branch:" update-rule-metadata/action.yml | grep -q "default.*master"; then
105+
echo "✓ branch input has default value of master"
106+
else
107+
echo "✗ branch input does not have default value of master"
108+
exit 1
109+
fi
110+
111+
# Test that checkout uses the branch input
112+
if grep -A2 "actions/checkout@v4" update-rule-metadata/action.yml | grep -q "ref.*inputs.branch"; then
113+
echo "✓ checkout step uses branch input"
114+
else
115+
echo "✗ checkout step does not use branch input"
116+
exit 1
117+
fi
118+
119+
# Test that PR creation uses the branch input for base
120+
if grep -A20 "peter-evans/create-pull-request" update-rule-metadata/action.yml | grep -q "base.*inputs.branch"; then
121+
echo "✓ PR creation uses branch input for base"
122+
else
123+
echo "✗ PR creation does not use branch input for base"
124+
exit 1
125+
fi
126+
127+
echo "✓ Branch parameter structure test completed successfully!"
73128
74129
output-validation:
75-
name: Test Output Values
130+
name: Test Output Schema
76131
runs-on: ubuntu-latest
77132

78133
steps:
@@ -81,9 +136,107 @@ jobs:
81136

82137
- name: Verify Output Schema
83138
run: |
84-
echo "Validating action outputs are defined correctly"
85-
echo "Expected outputs:"
86-
echo " - has-changes: Boolean indicating if changes were detected"
87-
echo " - pull-request-url: URL of created PR (if changes exist)"
88-
echo " - summary: Summary of rule metadata updates"
139+
echo "Validating action outputs are defined correctly..."
140+
141+
# Check for has-changes output
142+
if grep -q "has-changes:" update-rule-metadata/action.yml; then
143+
echo "✓ has-changes output defined"
144+
else
145+
echo "✗ has-changes output not defined"
146+
exit 1
147+
fi
148+
149+
# Check for pull-request-url output
150+
if grep -q "pull-request-url:" update-rule-metadata/action.yml; then
151+
echo "✓ pull-request-url output defined"
152+
else
153+
echo "✗ pull-request-url output not defined"
154+
exit 1
155+
fi
156+
157+
# Check for summary output
158+
if grep -q "summary:" update-rule-metadata/action.yml; then
159+
echo "✓ summary output defined"
160+
else
161+
echo "✗ summary output not defined"
162+
exit 1
163+
fi
164+
165+
echo "✓ All expected outputs are defined"
89166
echo "✓ Output schema validation complete"
167+
168+
integration-tests:
169+
name: Integration Tests
170+
runs-on: ubuntu-latest
171+
permissions:
172+
id-token: write
173+
contents: write
174+
pull-requests: write
175+
176+
steps:
177+
- name: Checkout code
178+
uses: actions/checkout@v4
179+
180+
- name: Test Action Execution
181+
id: test-execution
182+
uses: ./update-rule-metadata
183+
with:
184+
branch: ${{ github.ref_name }}
185+
continue-on-error: true
186+
187+
- name: Check Outputs Available
188+
if: steps.test-execution.outcome == 'success'
189+
run: |
190+
echo "Testing outputs from successful execution..."
191+
echo "has-changes: ${{ steps.test-execution.outputs.has-changes }}"
192+
echo "summary: ${{ steps.test-execution.outputs.summary }}"
193+
if [ "${{ steps.test-execution.outputs.has-changes }}" = "true" ]; then
194+
echo "pull-request-url: ${{ steps.test-execution.outputs.pull-request-url }}"
195+
fi
196+
197+
- name: Verify Integration Test
198+
run: |
199+
echo "================================"
200+
echo "Integration Test Results:"
201+
echo "================================"
202+
echo "Execution outcome: ${{ steps.test-execution.outcome }}"
203+
204+
if [ "${{ steps.test-execution.outcome }}" = "success" ]; then
205+
echo "✓ Action executed successfully"
206+
echo " - Changes detected: ${{ steps.test-execution.outputs.has-changes }}"
207+
echo " - Summary available: ${{ steps.test-execution.outputs.summary != '' && 'Yes' || 'No' }}"
208+
else
209+
echo "⚠ Action failed (expected if vault credentials unavailable or no sonarpedia files exist)"
210+
echo " This is normal in test environments without proper setup"
211+
fi
212+
213+
echo "================================"
214+
echo "✓ Integration test completed"
215+
216+
validation-summary:
217+
name: Test Summary
218+
runs-on: ubuntu-latest
219+
needs: [input-parameter-tests, branch-parameter-tests, output-validation, integration-tests]
220+
if: always()
221+
222+
steps:
223+
- name: Summary
224+
run: |
225+
echo "================================"
226+
echo "Test Suite Summary"
227+
echo "================================"
228+
echo "Input Parameter Tests: ${{ needs.input-parameter-tests.result }}"
229+
echo "Branch Parameter Tests: ${{ needs.branch-parameter-tests.result }}"
230+
echo "Output Validation: ${{ needs.output-validation.result }}"
231+
echo "Integration Tests: ${{ needs.integration-tests.result }}"
232+
echo "================================"
233+
234+
if [[ "${{ needs.input-parameter-tests.result }}" == "success" && \
235+
"${{ needs.branch-parameter-tests.result }}" == "success" && \
236+
"${{ needs.output-validation.result }}" == "success" ]]; then
237+
echo "✓ All validation tests passed!"
238+
echo "✓ Action is properly configured and ready to use"
239+
else
240+
echo "✗ Some tests failed - please review the results above"
241+
exit 1
242+
fi

0 commit comments

Comments
 (0)