-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathtestEnvFiles.test.ts
More file actions
61 lines (48 loc) · 1.81 KB
/
testEnvFiles.test.ts
File metadata and controls
61 lines (48 loc) · 1.81 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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------*/
import assert from 'assert';
import path from 'path';
import fs from 'fs';
import os from 'os';
import { parseEnvFiles } from '../../src/utils/envUtils';
suite('parseEnvFiles Tests', () => {
let tmpDir: string;
setup(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'go-test-env-'));
});
teardown(() => {
if (tmpDir && fs.existsSync(tmpDir)) {
fs.rmdirSync(tmpDir, { recursive: true });
}
});
test('should handle empty array', () => {
const result = parseEnvFiles([]);
assert.deepStrictEqual(result, {});
});
test('should handle undefined input', () => {
const result = parseEnvFiles(undefined);
assert.deepStrictEqual(result, {});
});
test('should handle array of files', () => {
const envFile1 = path.join(tmpDir, 'first.env');
const envFile2 = path.join(tmpDir, 'second.env');
fs.writeFileSync(envFile1, 'VAR1=value1\nSHARED=from_first');
fs.writeFileSync(envFile2, 'VAR2=value2\nSHARED=from_second');
const result = parseEnvFiles([envFile1, envFile2]);
assert.strictEqual(result.VAR1, 'value1');
assert.strictEqual(result.VAR2, 'value2');
// Later files should override earlier ones
assert.strictEqual(result.SHARED, 'from_second');
});
test('should handle mixed valid and invalid files', () => {
const validFile = path.join(tmpDir, 'valid.env');
const invalidFile = path.join(tmpDir, 'nonexistent.env');
fs.writeFileSync(validFile, 'VALID_VAR=valid_value');
// This should throw when trying to parse invalid file
assert.throws(() => {
parseEnvFiles([validFile, invalidFile]);
});
});
});