mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Add mockCCR helper to testing-utils
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
import { computeAutomationID } from "./api-client";
|
||||
import { EnvVar } from "./environment";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { mockCCR, setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
@@ -258,8 +258,8 @@ test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => {
|
||||
});
|
||||
|
||||
test("isCCR() returns true when expected", (t) => {
|
||||
process.env.GITHUB_EVENT_NAME = "dynamic";
|
||||
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
|
||||
mockCCR();
|
||||
|
||||
t.assert(isCCR());
|
||||
t.false(isDefaultSetup());
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@ import * as path from "path";
|
||||
import test from "ava";
|
||||
|
||||
import * as defaults from "./defaults.json";
|
||||
import { EnvVar } from "./environment";
|
||||
import {
|
||||
Feature,
|
||||
featureConfig,
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
getRecordingLogger,
|
||||
initializeFeatures,
|
||||
LoggedMessage,
|
||||
mockCCR,
|
||||
mockCodeQLVersion,
|
||||
mockFeatureFlagApiEndpoint,
|
||||
setupTests,
|
||||
@@ -547,8 +547,8 @@ test("initFeatures returns a `Features` instance by default", async (t) => {
|
||||
|
||||
test("initFeatures returns an `OfflineFeatures` instance in CCR", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_EVENT_NAME = "dynamic";
|
||||
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
|
||||
mockCCR();
|
||||
|
||||
const features = setUpFeatureFlagTests(tmpDir);
|
||||
t.is("OfflineFeatures", features.constructor.name);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import { CachingKind } from "./caching-utils";
|
||||
import * as codeql from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { EnvVar } from "./environment";
|
||||
import {
|
||||
CodeQLDefaultVersionInfo,
|
||||
Feature,
|
||||
@@ -436,3 +437,9 @@ export function makeTestToken(length: number = 36) {
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return chars.repeat(Math.ceil(length / chars.length)).slice(0, length);
|
||||
}
|
||||
|
||||
/** Sets the environment variables needed for isCCR() to be `true`. */
|
||||
export function mockCCR() {
|
||||
process.env.GITHUB_EVENT_NAME = "dynamic";
|
||||
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user