|
1 | 1 | import * as ADCSDK from '@api7/adc-sdk';
|
2 | 2 |
|
3 |
| -import { fillLabels, recursiveRemoveMetadataField } from './utils'; |
| 3 | +import { |
| 4 | + fillLabels, |
| 5 | + recursiveRemoveMetadataField, |
| 6 | + recursiveReplaceEnvVars, |
| 7 | +} from './utils'; |
4 | 8 |
|
5 | 9 | describe('CLI utils', () => {
|
6 | 10 | it('should fill label selector for local resources', () => {
|
@@ -249,4 +253,83 @@ describe('CLI utils', () => {
|
249 | 253 | ssls: [{ certificates: [], snis: ['test'] }],
|
250 | 254 | });
|
251 | 255 | });
|
| 256 | + |
| 257 | + describe('Environment Variables', () => { |
| 258 | + it('mock config', () => { |
| 259 | + const config: ADCSDK.Configuration = { |
| 260 | + services: [ |
| 261 | + { |
| 262 | + name: 'Test ${NAME}', |
| 263 | + routes: [ |
| 264 | + { |
| 265 | + name: 'Test ${NAME}', |
| 266 | + uris: ['/test/${NAME}'], |
| 267 | + }, |
| 268 | + ], |
| 269 | + }, |
| 270 | + ], |
| 271 | + consumers: [ |
| 272 | + { |
| 273 | + username: 'TEST_${NAME}', |
| 274 | + plugins: { |
| 275 | + 'key-auth': { |
| 276 | + key: '${SECRET}', |
| 277 | + }, |
| 278 | + }, |
| 279 | + }, |
| 280 | + ], |
| 281 | + ssls: [ |
| 282 | + { |
| 283 | + snis: ['test.com'], |
| 284 | + certificates: [ |
| 285 | + { |
| 286 | + certificate: '${CERT}', |
| 287 | + key: '${KEY}', |
| 288 | + }, |
| 289 | + ], |
| 290 | + }, |
| 291 | + ], |
| 292 | + global_rules: { |
| 293 | + // object key contains variables will not be parsed |
| 294 | + '${GLOBAL_PLUGIN}': { |
| 295 | + key: '${SECRET}', |
| 296 | + }, |
| 297 | + }, |
| 298 | + plugin_metadata: { |
| 299 | + 'file-logger': { |
| 300 | + log_format: { |
| 301 | + note: '${NOTE}', |
| 302 | + }, |
| 303 | + }, |
| 304 | + }, |
| 305 | + }; |
| 306 | + expect( |
| 307 | + recursiveReplaceEnvVars(config, { |
| 308 | + NAME: 'name', |
| 309 | + SECRET: 'secret', |
| 310 | + CERT: '-----', |
| 311 | + KEY: '-----', |
| 312 | + NOTE: 'note', |
| 313 | + }), |
| 314 | + ).toEqual({ |
| 315 | + consumers: [ |
| 316 | + { plugins: { 'key-auth': { key: 'secret' } }, username: 'TEST_name' }, |
| 317 | + ], |
| 318 | + global_rules: { '${GLOBAL_PLUGIN}': { key: 'secret' } }, |
| 319 | + plugin_metadata: { 'file-logger': { log_format: { note: 'note' } } }, |
| 320 | + services: [ |
| 321 | + { |
| 322 | + name: 'Test name', |
| 323 | + routes: [{ name: 'Test name', uris: ['/test/name'] }], |
| 324 | + }, |
| 325 | + ], |
| 326 | + ssls: [ |
| 327 | + { |
| 328 | + certificates: [{ certificate: '-----', key: '-----' }], |
| 329 | + snis: ['test.com'], |
| 330 | + }, |
| 331 | + ], |
| 332 | + }); |
| 333 | + }); |
| 334 | + }); |
252 | 335 | });
|
0 commit comments