-
Notifications
You must be signed in to change notification settings - Fork 0
278 lines (232 loc) · 8.92 KB
/
test.yml
File metadata and controls
278 lines (232 loc) · 8.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
name: Test Action
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
test-action:
name: Test MKP Builder Action
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create test plugin structure
run: |
# Create a minimal CheckMK plugin structure for testing
mkdir -p local/share/check_mk/agents/plugins
mkdir -p local/lib/python3/cmk_addons/plugins/test_plugin/agent_based
# Create test agent plugin
cat > local/share/check_mk/agents/plugins/test_plugin << 'EOF'
#!/bin/bash
echo "<<<test_plugin>>>"
echo "test_data 42"
EOF
chmod +x local/share/check_mk/agents/plugins/test_plugin
# Create test check plugin
cat > local/lib/python3/cmk_addons/plugins/test_plugin/agent_based/test_plugin.py << 'EOF'
from cmk.agent_based.v2 import *
def discover_test_plugin(section):
yield Service()
def check_test_plugin(section):
yield Result(state=State.OK, summary="Test plugin working")
register.agent_section(
name="test_plugin",
parse_function=lambda string_table: string_table,
)
register.check_plugin(
name="test_plugin",
service_name="Test Plugin",
discovery_function=discover_test_plugin,
check_function=check_test_plugin,
)
EOF
# Create test config
cat > .mkp-builderrc << 'EOF'
PACKAGE_NAME="test_plugin"
PACKAGE_TITLE="Test Plugin"
PACKAGE_AUTHOR="Test Author <test@example.com>"
PACKAGE_DESCRIPTION="A test plugin for CI/CD"
CMK_MIN_VERSION="2.3.0p1"
CMK_PACKAGED_VERSION="2.3.0p34"
VALIDATE_PYTHON="yes"
EOF
- name: Test Action
id: test
uses: ./
with:
version: '1.0.0-test'
verbose: 'true'
- name: Verify Output
run: |
echo "Package file: ${{ steps.test.outputs.package-file }}"
echo "Package name: ${{ steps.test.outputs.package-name }}"
echo "Package size: ${{ steps.test.outputs.package-size }}"
# Verify the package exists
if [[ ! -f "${{ steps.test.outputs.package-file }}" ]]; then
echo "::error::Package file not found!"
exit 1
fi
# Verify it's a valid tar.gz file
if ! tar -tzf "${{ steps.test.outputs.package-file }}" >/dev/null 2>&1; then
echo "::error::Package is not a valid tar.gz file!"
exit 1
fi
# Verify outputs are not empty
if [[ -z "${{ steps.test.outputs.package-name }}" ]]; then
echo "::error::Package name output is empty!"
exit 1
fi
if [[ -z "${{ steps.test.outputs.package-size }}" ]]; then
echo "::error::Package size output is empty!"
exit 1
fi
# Check package contents
echo "Package contents:"
tar -tzf "${{ steps.test.outputs.package-file }}"
# Verify expected files are in the package
if ! tar -tzf "${{ steps.test.outputs.package-file }}" | grep -q "info$"; then
echo "::error::Package missing info file!"
exit 1
fi
echo "::notice::Action test completed successfully!"
test-with-all-inputs:
name: Test with All Inputs
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create test plugin structure
run: |
mkdir -p local/share/check_mk/agents/plugins
mkdir -p local/lib/python3/cmk_addons/plugins/advanced_plugin/agent_based
cat > local/share/check_mk/agents/plugins/advanced_plugin << 'EOF'
#!/bin/bash
echo "<<<advanced_plugin>>>"
echo "advanced_data 123"
EOF
chmod +x local/share/check_mk/agents/plugins/advanced_plugin
cat > local/lib/python3/cmk_addons/plugins/advanced_plugin/agent_based/advanced_plugin.py << 'EOF'
from cmk.agent_based.v2 import *
def discover_advanced_plugin(section):
yield Service()
def check_advanced_plugin(section):
yield Result(state=State.OK, summary="Advanced plugin working")
register.agent_section(
name="advanced_plugin",
parse_function=lambda string_table: string_table,
)
register.check_plugin(
name="advanced_plugin",
service_name="Advanced Plugin",
discovery_function=discover_advanced_plugin,
check_function=check_advanced_plugin,
)
EOF
- name: Test Action with All Inputs
id: test-full
uses: ./
with:
version: '2.0.0-test'
package-name: 'advanced_plugin'
title: 'Advanced Test Plugin'
author: 'Test Developer <dev@example.com>'
description: 'An advanced plugin for comprehensive testing'
cmk-min-version: '2.3.0p1'
cmk-packaged-version: '2.3.0p34'
version-usable-until: '2.4.0'
download-url: 'https://github.com/test/advanced-plugin'
output-dir: 'dist'
validate-python: 'true'
verbose: 'true'
- name: Verify Full Test Output
run: |
echo "Testing with all inputs provided"
# Verify package was created in correct directory
if [[ ! -f "${{ steps.test-full.outputs.package-file }}" ]]; then
echo "::error::Package not found in specified output directory!"
exit 1
fi
# Verify package name matches input
if [[ "${{ steps.test-full.outputs.package-name }}" != "advanced_plugin" ]]; then
echo "::error::Package name doesn't match input!"
exit 1
fi
echo "::notice::All inputs test completed successfully!"
test-validation-errors:
name: Test Input Validation
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test Invalid Version Format
id: test-invalid-version
continue-on-error: true
uses: ./
with:
version: 'invalid-version'
- name: Verify Version Validation
run: |
if [[ "${{ steps.test-invalid-version.outcome }}" != "failure" ]]; then
echo "::error::Action should have failed with invalid version!"
exit 1
fi
echo "::notice::Version validation working correctly"
- name: Test Invalid Boolean Input
id: test-invalid-boolean
continue-on-error: true
uses: ./
with:
version: '1.0.0'
validate-python: 'maybe'
- name: Verify Boolean Validation
run: |
if [[ "${{ steps.test-invalid-boolean.outcome }}" != "failure" ]]; then
echo "::error::Action should have failed with invalid boolean!"
exit 1
fi
echo "::notice::Boolean validation working correctly"
test-no-python:
name: Test Without Python Validation
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create simple plugin structure (no Python files)
run: |
mkdir -p local/share/check_mk/agents/plugins
# Create simple agent plugin without Python
cat > local/share/check_mk/agents/plugins/simple_plugin << 'EOF'
#!/bin/bash
echo "<<<simple_plugin>>>"
echo "simple_data 1"
EOF
chmod +x local/share/check_mk/agents/plugins/simple_plugin
- name: Test Action Without Python Validation
id: test-no-python
uses: ./
with:
version: '1.0.0-no-python'
validate-python: 'false'
verbose: 'true'
- name: Verify No-Python Test Output
run: |
echo "Testing without Python validation - should be faster"
# Verify package was created
if [[ ! -f "${{ steps.test-no-python.outputs.package-file }}" ]]; then
echo "::error::Package not found!"
exit 1
fi
# Verify it's a valid package
if ! tar -tzf "${{ steps.test-no-python.outputs.package-file }}" >/dev/null 2>&1; then
echo "::error::Package is not a valid tar.gz file!"
exit 1
fi
echo "::notice::No-Python test completed successfully - Python setup was skipped!"