Skip to content

Commit 2a99c8b

Browse files
committed
build: add a test workflow
1 parent 1328dab commit 2a99c8b

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

.github/workflows/test.yml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Test Send CDEvents Action
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
env:
11+
VALID_CDEVENT: '{"context":{"version":"0.3.0","id":"test-${{ github.run_id }}","source":"github-action-test","type":"dev.cdevents.build.started.0.1.1","timestamp":"2024-01-01T00:00:00Z"},"subject":{"id":"test-subject","source":"https://github.com/test/repo"}}'
12+
INVALID_CDEVENT: '{"invalid": "missing required fields"}'
13+
14+
jobs:
15+
test-basic:
16+
name: Test Basic Functionality
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Test with valid CDEvent (debug sink)
23+
uses: ./
24+
with:
25+
data: ${{ env.VALID_CDEVENT }}
26+
27+
test-with-url:
28+
name: Test with HTTP URL
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Start HTTP server
35+
run: |
36+
python3 -m http.server 8080 --bind 127.0.0.1 &
37+
echo $! > server.pid
38+
sleep 2
39+
40+
- name: Test with HTTP endpoint
41+
uses: ./
42+
with:
43+
data: ${{ env.VALID_CDEVENT }}
44+
url: "http://127.0.0.1:8080/"
45+
46+
- name: Stop HTTP server
47+
if: always()
48+
run: |
49+
if [ -f server.pid ]; then
50+
kill $(cat server.pid) || true
51+
rm server.pid
52+
fi
53+
54+
test-with-headers:
55+
name: Test with Custom Headers
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
61+
- name: Start HTTP server
62+
run: |
63+
python3 -m http.server 8080 --bind 127.0.0.1 &
64+
echo $! > server.pid
65+
sleep 2
66+
67+
- name: Test with custom headers
68+
uses: ./
69+
with:
70+
data: ${{ env.VALID_CDEVENT }}
71+
url: "http://127.0.0.1:8080/"
72+
headers: |
73+
X-API-Key: test-key-123
74+
X-Source: github-actions
75+
76+
- name: Stop HTTP server
77+
if: always()
78+
run: |
79+
if [ -f server.pid ]; then
80+
kill $(cat server.pid) || true
81+
rm server.pid
82+
fi
83+
84+
test-with-config:
85+
name: Test with Configuration
86+
runs-on: ubuntu-latest
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v4
90+
91+
- name: Test with TOML config
92+
uses: ./
93+
with:
94+
data: ${{ env.VALID_CDEVENT }}
95+
config: |
96+
[sinks.debug]
97+
enabled = true
98+
type = "debug"
99+
100+
test-with-env-vars:
101+
name: Test with Environment Variables
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v4
106+
107+
- name: Test with env var overrides
108+
uses: ./
109+
env:
110+
CDVIZ_COLLECTOR__SINKS__DEBUG__ENABLED: "true"
111+
with:
112+
data: ${{ env.VALID_CDEVENT }}
113+
114+
test-with-file:
115+
name: Test with File Input
116+
runs-on: ubuntu-latest
117+
steps:
118+
- name: Checkout
119+
uses: actions/checkout@v4
120+
121+
- name: Create test data file
122+
run: echo '${{ env.VALID_CDEVENT }}' > test-event.json
123+
124+
- name: Test with file input
125+
uses: ./
126+
with:
127+
data: '@test-event.json'
128+
129+
- name: Clean up
130+
if: always()
131+
run: rm -f test-event.json
132+
133+
test-cleanup:
134+
name: Test Config File Cleanup
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Checkout
138+
uses: actions/checkout@v4
139+
140+
- name: Test config cleanup
141+
uses: ./
142+
with:
143+
data: ${{ env.VALID_CDEVENT }}
144+
config: |
145+
[sinks.debug]
146+
enabled = true
147+
148+
- name: Verify cleanup
149+
run: |
150+
if ls .cdviz-config-*.toml 2>/dev/null; then
151+
echo "ERROR: Config files not cleaned up!"
152+
exit 1
153+
fi
154+
echo "SUCCESS: Config files cleaned up"
155+
156+
test-error-handling:
157+
name: Test Error Cases
158+
runs-on: ubuntu-latest
159+
steps:
160+
- name: Checkout
161+
uses: actions/checkout@v4
162+
163+
- name: Test with invalid CDEvent
164+
id: invalid-data
165+
continue-on-error: true
166+
uses: ./
167+
with:
168+
data: ${{ env.INVALID_CDEVENT }}
169+
170+
- name: Test with unreachable URL
171+
id: unreachable
172+
continue-on-error: true
173+
uses: ./
174+
with:
175+
data: ${{ env.VALID_CDEVENT }}
176+
url: "http://unreachable.example.com/"
177+
178+
- name: Verify error handling
179+
run: |
180+
echo "Invalid data result: ${{ steps.invalid-data.outcome }}"
181+
echo "Unreachable URL result: ${{ steps.unreachable.outcome }}"
182+
echo "Both tests completed (may have failed as expected)"
183+
184+
test-different-versions:
185+
name: Test Container Versions
186+
runs-on: ubuntu-latest
187+
strategy:
188+
matrix:
189+
version: ['latest']
190+
steps:
191+
- name: Checkout
192+
uses: actions/checkout@v4
193+
194+
- name: Test version ${{ matrix.version }}
195+
uses: ./
196+
with:
197+
data: ${{ env.VALID_CDEVENT }}
198+
version: ${{ matrix.version }}

0 commit comments

Comments
 (0)