Skip to content

Commit 35b5e3c

Browse files
committed
fix(env): Extend env with global variables
1 parent ab79d5f commit 35b5e3c

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/lib/ggshield-api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ export function ggshieldApiKey(
317317
console.log(proc.stderr);
318318
return undefined;
319319
} else {
320-
console.log(proc.stdout);
321320
const apiUrl = configuration.apiUrl;
322321

323322
const regexInstanceSection = `\\[${apiToDashboard(

src/lib/run-ggshield.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@ export function runGGShieldCommand(
2020
args: string[]
2121
): SpawnSyncReturns<string> {
2222
const { ggshieldPath, apiUrl, apiKey } = configuration;
23-
let env: {
24-
GITGUARDIAN_API_URL: string;
25-
GG_USER_AGENT: string;
26-
GITGUARDIAN_API_KEY?: string;
27-
} = {
23+
let env: NodeJS.ProcessEnv = {
24+
...process.env,
2825
GITGUARDIAN_API_URL: apiUrl,
2926
GG_USER_AGENT: "gitguardian-vscode",
3027
};
3128

3229
if (apiKey) {
33-
env = {
34-
...env,
35-
GITGUARDIAN_API_KEY: apiKey,
36-
};
30+
env.GITGUARDIAN_API_KEY = apiKey;
3731
}
3832

3933
let options: SpawnSyncOptionsWithStringEncoding = {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as simple from "simple-mock";
2+
import * as childProcess from "child_process";
3+
import * as runGGShield from "../../../lib/run-ggshield";
4+
import assert = require("assert");
5+
import { GGShieldConfiguration } from "../../../lib/ggshield-configuration";
6+
7+
suite("runGGShieldCommand", () => {
8+
let spawnSyncMock: simple.Stub<Function>;
9+
10+
setup(() => {
11+
spawnSyncMock = simple.mock(childProcess, "spawnSync"); // Mock spawnSync
12+
});
13+
14+
teardown(() => {
15+
simple.restore();
16+
});
17+
18+
test("Global env variables are set correctly", async () => {
19+
process.env.TEST_GLOBAL_VAR = "GlobalValue";
20+
21+
const spawnSyncSpy = simple.mock(childProcess, "spawnSync");
22+
runGGShield.runGGShieldCommand(
23+
{
24+
ggshieldPath: "path/to/ggshield",
25+
apiUrl: "",
26+
apiKey: "",
27+
} as GGShieldConfiguration,
28+
[]
29+
);
30+
31+
// Assert that spawnSync was called
32+
assert(spawnSyncSpy.called, "spawnSync should be called once");
33+
34+
// Check the arguments passed to spawnSync
35+
const spawnSyncArgs = spawnSyncSpy.lastCall.args;
36+
const options = spawnSyncArgs[2];
37+
assert.strictEqual(options.env.TEST_GLOBAL_VAR, "GlobalValue");
38+
39+
simple.restore();
40+
delete process.env.TEST_GLOBAL_VAR;
41+
});
42+
});

0 commit comments

Comments
 (0)