-
-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathenvResolver.ts
More file actions
68 lines (55 loc) · 2.43 KB
/
envResolver.ts
File metadata and controls
68 lines (55 loc) · 2.43 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
import { assert } from 'chai'
import { describe, it, beforeEach, afterEach } from 'mocha'
import { resolveEnvVariables } from '../envResolver'
describe('Environment Variable Resolution', () => {
let originalEnv: NodeJS.ProcessEnv
beforeEach(() => {
originalEnv = { ...process.env }
})
afterEach(() => {
process.env = originalEnv
})
it('should resolve ${env:VAR_NAME} with existing environment variable', () => {
process.env.TEST_VAR = '/test/path'
const result = resolveEnvVariables('${env:TEST_VAR}/subdir')
assert.equal(result, '/test/path/subdir')
})
it('should keep ${env:VAR_NAME} if environment variable does not exist', () => {
delete process.env.NONEXISTENT_VAR
const result = resolveEnvVariables('${env:NONEXISTENT_VAR}/subdir')
assert.equal(result, '${env:NONEXISTENT_VAR}/subdir')
})
it('should resolve multiple environment variables', () => {
process.env.VAR1 = '/path1'
process.env.VAR2 = '/path2'
const result = resolveEnvVariables('${env:VAR1}/${env:VAR2}')
assert.equal(result, '/path1//path2')
})
it('should handle text without environment variables', () => {
const result = resolveEnvVariables('/var/www/html')
assert.equal(result, '/var/www/html')
})
it('should handle environment variables with underscores and numbers', () => {
process.env.MY_VAR_123 = '/custom/path'
const result = resolveEnvVariables('${env:MY_VAR_123}')
assert.equal(result, '/custom/path')
})
it('should handle empty environment variable value', () => {
process.env.EMPTY_VAR = ''
const result = resolveEnvVariables('${env:EMPTY_VAR}/test')
assert.equal(result, '/test')
})
it('should handle mixed content', () => {
process.env.DOCKER_ROOT = '/var/www/html'
const result = resolveEnvVariables('prefix/${env:DOCKER_ROOT}/suffix')
assert.equal(result, 'prefix//var/www/html/suffix')
})
it('should handle pathMapping use case', () => {
process.env.DOCKER_WEB_ROOT = '/var/www/html'
process.env.LOCAL_PROJECT = '/Users/developer/myproject'
const serverPath = '${env:DOCKER_WEB_ROOT}'
const localPath = '${env:LOCAL_PROJECT}'
assert.equal(resolveEnvVariables(serverPath), '/var/www/html')
assert.equal(resolveEnvVariables(localPath), '/Users/developer/myproject')
})
})