-
Notifications
You must be signed in to change notification settings - Fork 1
267 lines (234 loc) · 11 KB
/
test.yml
File metadata and controls
267 lines (234 loc) · 11 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
name: Test Quant Cloud Init Action
# Tests the quant-cloud-init-action with various scenarios:
# - Valid credentials and main branch logic
# - Invalid credentials (expected failures)
# - Non-existent applications (warnings)
# - Override functionality (app, environment, master branch)
# - Feature branch logic (unique environments and image tags)
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'src/**'
- '.github/workflows/test.yml'
- 'package.json'
- 'package-lock.json'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
test-scenario: [
'valid-credentials',
'invalid-api-key',
'invalid-organization',
'non-existent-application',
'test-overrides'
]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
run: npm ci
- name: Build with ncc
run: npx ncc build src/index.ts
- name: Debug Action Files
run: |
ls -la
ls -la dist/
cat action.yml
- name: Test Valid Credentials
if: matrix.test-scenario == 'valid-credentials'
uses: ./
id: init-valid
with:
quant_api_key: ${{ secrets.QUANT_API_KEY }}
quant_organization: 'quant'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: false
- name: Test Invalid API Key (Expected Failure)
if: matrix.test-scenario == 'invalid-api-key'
uses: ./
id: init-invalid-key
with:
quant_api_key: 'invalid-key-12345'
quant_organization: 'quant'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: true
- name: Test Invalid Organization (Expected Failure)
if: matrix.test-scenario == 'invalid-organization'
uses: ./
id: init-invalid-org
with:
quant_api_key: ${{ secrets.QUANT_API_KEY }}
quant_organization: 'non-existent-org-12345'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: true
- name: Test Non-Existent Application (Expected Warning)
if: matrix.test-scenario == 'non-existent-application'
uses: ./
id: init-no-app
with:
quant_api_key: ${{ secrets.QUANT_API_KEY }}
quant_organization: 'quant'
quant_application: 'non-existent-app-12345'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: false
- name: Test Overrides
if: matrix.test-scenario == 'test-overrides'
uses: ./
id: init-overrides
with:
quant_api_key: ${{ secrets.QUANT_API_KEY }}
quant_organization: 'quant'
quant_application: 'test-override-app'
environment_name_override: 'staging'
master_branch_override: 'develop'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: false
- name: Test Feature Branch Logic (with overrides)
if: matrix.test-scenario == 'test-overrides'
uses: ./
id: init-feature-branch
with:
quant_api_key: ${{ secrets.QUANT_API_KEY }}
quant_organization: 'quant'
quant_application: 'feature-test-app'
# Simulate feature branch by overriding environment name
environment_name_override: 'feature-my-big-feature'
base_url: 'https://portal.stage.quantcdn.io/api/v3'
continue-on-error: false
- name: Validate Valid Credentials Outputs
if: matrix.test-scenario == 'valid-credentials'
run: |
echo "=== VALID CREDENTIALS TEST RESULTS ==="
echo "Project exists: ${{ steps.init-valid.outputs.project_exists }}"
echo "Environment exists: ${{ steps.init-valid.outputs.environment_exists }}"
echo "Application: ${{ steps.init-valid.outputs.quant_application }}"
echo "Environment: ${{ steps.init-valid.outputs.environment_name }}"
echo "Is production: ${{ steps.init-valid.outputs.is_production }}"
echo "Stripped endpoint: ${{ steps.init-valid.outputs.stripped_endpoint }}"
echo "Image suffix: ${{ steps.init-valid.outputs.image_suffix }}"
# Validate expected values for main branch
if [[ "${{ steps.init-valid.outputs.environment_name }}" != "production" ]]; then
echo "❌ Expected environment 'production', got '${{ steps.init-valid.outputs.environment_name }}'"
exit 1
fi
if [[ "${{ steps.init-valid.outputs.is_production }}" != "true" ]]; then
echo "❌ Expected is_production 'true', got '${{ steps.init-valid.outputs.is_production }}'"
exit 1
fi
if [[ "${{ steps.init-valid.outputs.image_suffix }}" != "-latest" ]]; then
echo "❌ Expected image_suffix '-latest', got '${{ steps.init-valid.outputs.image_suffix }}'"
exit 1
fi
echo "✅ Valid credentials test passed"
- name: Validate Invalid API Key Failure
if: matrix.test-scenario == 'invalid-api-key'
run: |
echo "=== INVALID API KEY TEST RESULTS ==="
if [[ "${{ steps.init-invalid-key.outcome }}" == "failure" ]]; then
echo "✅ Invalid API key correctly failed as expected"
else
echo "❌ Invalid API key should have failed but didn't"
exit 1
fi
- name: Validate Invalid Organization Failure
if: matrix.test-scenario == 'invalid-organization'
run: |
echo "=== INVALID ORGANIZATION TEST RESULTS ==="
if [[ "${{ steps.init-invalid-org.outcome }}" == "failure" ]]; then
echo "✅ Invalid organization correctly failed as expected"
else
echo "❌ Invalid organization should have failed but didn't"
exit 1
fi
- name: Validate Non-Existent Application Warning
if: matrix.test-scenario == 'non-existent-application'
run: |
echo "=== NON-EXISTENT APPLICATION TEST RESULTS ==="
echo "Project exists: ${{ steps.init-no-app.outputs.project_exists }}"
echo "Application: ${{ steps.init-no-app.outputs.quant_application }}"
if [[ "${{ steps.init-no-app.outputs.project_exists }}" == "false" ]]; then
echo "✅ Non-existent application correctly identified as not existing"
else
echo "❌ Non-existent application should show project_exists=false"
exit 1
fi
if [[ "${{ steps.init-no-app.outputs.quant_application }}" == "non-existent-app-12345" ]]; then
echo "✅ Application name correctly set to provided value"
else
echo "❌ Application name should match provided value"
exit 1
fi
echo "✅ Non-existent application test passed"
- name: Validate Overrides
if: matrix.test-scenario == 'test-overrides'
run: |
echo "=== OVERRIDES TEST RESULTS ==="
echo "Application: ${{ steps.init-overrides.outputs.quant_application }}"
echo "Environment: ${{ steps.init-overrides.outputs.environment_name }}"
echo "Is production: ${{ steps.init-overrides.outputs.is_production }}"
# Test quant_application override
if [[ "${{ steps.init-overrides.outputs.quant_application }}" != "test-override-app" ]]; then
echo "❌ Expected application 'test-override-app', got '${{ steps.init-overrides.outputs.quant_application }}'"
exit 1
fi
# Test environment_name_override
if [[ "${{ steps.init-overrides.outputs.environment_name }}" != "staging" ]]; then
echo "❌ Expected environment 'staging', got '${{ steps.init-overrides.outputs.environment_name }}'"
exit 1
fi
# Test master_branch_override (should affect is_production)
if [[ "${{ steps.init-overrides.outputs.is_production }}" != "false" ]]; then
echo "❌ Expected is_production 'false' with master_branch_override='develop', got '${{ steps.init-overrides.outputs.is_production }}'"
exit 1
fi
# Test image suffix with overrides
# When environment is overridden, image suffix should match the environment name
if [[ "${{ steps.init-overrides.outputs.image_suffix }}" != "-staging" ]]; then
echo "❌ Expected image_suffix '-staging' with environment_name_override='staging', got '${{ steps.init-overrides.outputs.image_suffix }}'"
exit 1
fi
echo "✅ All overrides test passed"
- name: Validate Feature Branch Logic
if: matrix.test-scenario == 'test-overrides'
run: |
echo "=== FEATURE BRANCH LOGIC TEST RESULTS ==="
echo "Application: ${{ steps.init-feature-branch.outputs.quant_application }}"
echo "Environment: ${{ steps.init-feature-branch.outputs.environment_name }}"
echo "Is production: ${{ steps.init-feature-branch.outputs.is_production }}"
echo "Image suffix: ${{ steps.init-feature-branch.outputs.image_suffix }}"
# Test feature branch environment name
if [[ "${{ steps.init-feature-branch.outputs.environment_name }}" != "feature-my-big-feature" ]]; then
echo "❌ Expected environment 'feature-my-big-feature', got '${{ steps.init-feature-branch.outputs.environment_name }}'"
exit 1
fi
# Test feature branch image suffix (should match environment name)
if [[ "${{ steps.init-feature-branch.outputs.image_suffix }}" != "-feature-my-big-feature" ]]; then
echo "❌ Expected image_suffix '-feature-my-big-feature', got '${{ steps.init-feature-branch.outputs.image_suffix }}'"
exit 1
fi
# Test that feature branches are not production
if [[ "${{ steps.init-feature-branch.outputs.is_production }}" != "false" ]]; then
echo "❌ Expected is_production 'false' for feature branch, got '${{ steps.init-feature-branch.outputs.is_production }}'"
exit 1
fi
echo "✅ Feature branch logic test passed"
- name: Test Summary
run: |
echo "=== TEST SUMMARY ==="
echo "Test scenario: ${{ matrix.test-scenario }}"
echo "Job status: ${{ job.status }}"
echo "Step outcomes:"
echo " - Valid credentials: ${{ steps.init-valid.outcome || 'N/A' }}"
echo " - Invalid API key: ${{ steps.init-invalid-key.outcome || 'N/A' }}"
echo " - Invalid org: ${{ steps.init-invalid-org.outcome || 'N/A' }}"
echo " - Non-existent app: ${{ steps.init-no-app.outcome || 'N/A' }}"
echo " - Overrides: ${{ steps.init-overrides.outcome || 'N/A' }}"
echo " - Feature branch logic: ${{ steps.init-feature-branch.outcome || 'N/A' }}"