Skip to content

Commit c80b611

Browse files
committed
Add mockCCR helper to testing-utils
1 parent a827b58 commit c80b611

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/actions-util.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { computeAutomationID } from "./api-client";
1313
import { EnvVar } from "./environment";
1414
import { getRunnerLogger } from "./logging";
15-
import { setupTests } from "./testing-utils";
15+
import { mockCCR, setupTests } from "./testing-utils";
1616
import { initializeEnvironment } from "./util";
1717

1818
setupTests(test);
@@ -258,8 +258,8 @@ test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => {
258258
});
259259

260260
test("isCCR() returns true when expected", (t) => {
261-
process.env.GITHUB_EVENT_NAME = "dynamic";
262-
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
261+
mockCCR();
262+
263263
t.assert(isCCR());
264264
t.false(isDefaultSetup());
265265
});

src/feature-flags.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import test from "ava";
55

66
import * as defaults from "./defaults.json";
7-
import { EnvVar } from "./environment";
87
import {
98
Feature,
109
featureConfig,
@@ -20,6 +19,7 @@ import {
2019
getRecordingLogger,
2120
initializeFeatures,
2221
LoggedMessage,
22+
mockCCR,
2323
mockCodeQLVersion,
2424
mockFeatureFlagApiEndpoint,
2525
setupTests,
@@ -547,8 +547,8 @@ test("initFeatures returns a `Features` instance by default", async (t) => {
547547

548548
test("initFeatures returns an `OfflineFeatures` instance in CCR", async (t) => {
549549
await withTmpDir(async (tmpDir) => {
550-
process.env.GITHUB_EVENT_NAME = "dynamic";
551-
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
550+
mockCCR();
551+
552552
const features = setUpFeatureFlagTests(tmpDir);
553553
t.is("OfflineFeatures", features.constructor.name);
554554
});

src/testing-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CachingKind } from "./caching-utils";
1414
import * as codeql from "./codeql";
1515
import { Config } from "./config-utils";
1616
import * as defaults from "./defaults.json";
17+
import { EnvVar } from "./environment";
1718
import {
1819
CodeQLDefaultVersionInfo,
1920
Feature,
@@ -436,3 +437,9 @@ export function makeTestToken(length: number = 36) {
436437
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
437438
return chars.repeat(Math.ceil(length / chars.length)).slice(0, length);
438439
}
440+
441+
/** Sets the environment variables needed for isCCR() to be `true`. */
442+
export function mockCCR() {
443+
process.env.GITHUB_EVENT_NAME = "dynamic";
444+
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
445+
}

0 commit comments

Comments
 (0)