Skip to content

Commit 2b21fb6

Browse files
committed
feat(tests): add secretmanager tests
1 parent f2996f5 commit 2b21fb6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

spec/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('index', () => {
6767

6868
import './lifecycle.spec';
6969
import './main.spec';
70+
import './secretmanager.spec';
7071
import './v2.spec';
7172
import './cloudevent/generate';
7273
import './app.spec';

spec/secretmanager.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect } from 'chai';
2+
import { mockSecretManager } from '../src/secretManager';
3+
4+
describe('mockSecretManager', () => {
5+
let originalEnv;
6+
7+
before(() => {
8+
// Capture the original environment variables
9+
originalEnv = { ...process.env };
10+
});
11+
12+
afterEach(() => {
13+
// Reset any mutations made by the test run
14+
process.env = { ...originalEnv };
15+
});
16+
17+
it('applies each key/value pair to process.env', () => {
18+
const conf = { FOO: 'bar', BAZ: 'qux' };
19+
20+
mockSecretManager(conf);
21+
22+
expect(process.env.FOO).to.equal('bar');
23+
expect(process.env.BAZ).to.equal('qux');
24+
});
25+
26+
it('overwrites an existing variable with the new value', () => {
27+
process.env.EXISTING = 'old';
28+
const conf = { EXISTING: 'new' };
29+
30+
mockSecretManager(conf);
31+
32+
expect(process.env.EXISTING).to.equal('new');
33+
});
34+
35+
it('supports non-string values (coerced to string)', () => {
36+
const conf: Record<string, string> = { NUM_VALUE: '123', BOOL_VALUE: 'true' };
37+
38+
mockSecretManager(conf);
39+
40+
expect(process.env.NUM_VALUE).to.equal('123');
41+
expect(process.env.BOOL_VALUE).to.equal('true');
42+
});
43+
});

0 commit comments

Comments
 (0)