Skip to content

Commit 6497074

Browse files
committed
feat(run-ggshield): Add test for '--allow-self-signed' flag in ggshield calls
1 parent 1085fe0 commit 6497074

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/test/suite/lib/run-ggshield.test.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ suite("runGGShieldCommand", () => {
1717

1818
test("Global env variables are set correctly", async () => {
1919
process.env.TEST_GLOBAL_VAR = "GlobalValue";
20-
21-
const spawnSyncSpy = simple.mock(childProcess, "spawnSync");
2220
runGGShield.runGGShieldCommand(
2321
{
2422
ggshieldPath: "path/to/ggshield",
@@ -29,14 +27,49 @@ suite("runGGShieldCommand", () => {
2927
);
3028

3129
// Assert that spawnSync was called
32-
assert(spawnSyncSpy.called, "spawnSync should be called once");
30+
assert(spawnSyncMock.called, "spawnSync should be called once");
3331

3432
// Check the arguments passed to spawnSync
35-
const spawnSyncArgs = spawnSyncSpy.lastCall.args;
33+
const spawnSyncArgs = spawnSyncMock.lastCall.args;
3634
const options = spawnSyncArgs[2];
3735
assert.strictEqual(options.env.TEST_GLOBAL_VAR, "GlobalValue");
3836

39-
simple.restore();
4037
delete process.env.TEST_GLOBAL_VAR;
4138
});
39+
40+
const testCasesAllowSelfSigned = [
41+
{
42+
allowSelfSigned: true,
43+
description:
44+
"GGshield is called with flag --allow-self-signed when allowSelfSigned is true",
45+
},
46+
{
47+
allowSelfSigned: false,
48+
description:
49+
"GGshield is not called with flag --allow-self-signed when allowSelfSigned is false",
50+
},
51+
];
52+
53+
testCasesAllowSelfSigned.forEach(({ allowSelfSigned, description }) => {
54+
test(description, async () => {
55+
process.env.TEST_GLOBAL_VAR = "GlobalValue";
56+
57+
runGGShield.runGGShieldCommand(
58+
{
59+
ggshieldPath: "path/to/ggshield",
60+
apiUrl: "",
61+
apiKey: "",
62+
allowSelfSigned: allowSelfSigned,
63+
} as GGShieldConfiguration,
64+
[]
65+
);
66+
67+
assert(spawnSyncMock.called, "spawnSync should be called once");
68+
69+
const spawnSyncArgs = spawnSyncMock.lastCall.args;
70+
const args = spawnSyncArgs[1];
71+
72+
assert.strictEqual(args.includes("--allow-self-signed"), allowSelfSigned);
73+
});
74+
});
4275
});

0 commit comments

Comments
 (0)