Add tests for toolcache bypassing
This commit is contained in:
parent
d45b0eba23
commit
e1cd41a365
3 changed files with 94 additions and 9 deletions
36
lib/codeql.test.js
generated
36
lib/codeql.test.js
generated
|
|
@ -79,7 +79,7 @@ ava_1.default.beforeEach(() => {
|
|||
trapCacheDownloadTime: 0,
|
||||
};
|
||||
});
|
||||
async function mockApiAndSetupCodeQL({ version, isPinned, tmpDir, toolsInput, apiDetails, }) {
|
||||
async function mockApiAndSetupCodeQL({ apiDetails, featureFlags, isPinned, tmpDir, toolsInput, version, }) {
|
||||
var _a;
|
||||
const platform = process.platform === "win32"
|
||||
? "win64"
|
||||
|
|
@ -93,7 +93,7 @@ async function mockApiAndSetupCodeQL({ version, isPinned, tmpDir, toolsInput, ap
|
|||
(0, nock_1.default)(baseUrl)
|
||||
.get(relativeUrl)
|
||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle${isPinned ? "-pinned" : ""}.tar.gz`));
|
||||
await codeql.setupCodeQL(toolsInput ? toolsInput.input : `${baseUrl}${relativeUrl}`, apiDetails !== null && apiDetails !== void 0 ? apiDetails : sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true), false);
|
||||
await codeql.setupCodeQL(toolsInput ? toolsInput.input : `${baseUrl}${relativeUrl}`, apiDetails !== null && apiDetails !== void 0 ? apiDetails : sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, featureFlags !== null && featureFlags !== void 0 ? featureFlags : (0, feature_flags_1.createFeatureFlags)([]), (0, logging_1.getRunnerLogger)(true), false);
|
||||
}
|
||||
(0, ava_1.default)("download codeql bundle cache", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
|
|
@ -168,6 +168,38 @@ async function mockApiAndSetupCodeQL({ version, isPinned, tmpDir, toolsInput, ap
|
|||
t.is(cachedVersions.length, 2);
|
||||
});
|
||||
});
|
||||
const TOOLCACHE_BYPASS_TEST_CASES = [
|
||||
[true, undefined, true],
|
||||
[false, undefined, false],
|
||||
[
|
||||
true,
|
||||
"https://github.com/github/codeql-action/releases/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
false,
|
||||
],
|
||||
];
|
||||
for (const [isFeatureFlagEnabled, toolsInput, shouldToolcacheBeBypassed,] of TOOLCACHE_BYPASS_TEST_CASES) {
|
||||
(0, ava_1.default)(`download codeql bundle ${shouldToolcacheBeBypassed ? "bypasses" : "does not bypass"} toolcache when feature flag ${isFeatureFlagEnabled ? "enabled" : "disabled"} and tools: ${toolsInput} passed`, async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
await mockApiAndSetupCodeQL({
|
||||
version: "codeql-bundle-20200601",
|
||||
apiDetails: sampleApiDetails,
|
||||
isPinned: true,
|
||||
tmpDir,
|
||||
});
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
await mockApiAndSetupCodeQL({
|
||||
version: defaults.bundleVersion,
|
||||
apiDetails: sampleApiDetails,
|
||||
featureFlags: (0, feature_flags_1.createFeatureFlags)(isFeatureFlagEnabled ? [feature_flags_1.FeatureFlag.BypassToolcacheEnabled] : []),
|
||||
toolsInput: { input: toolsInput },
|
||||
tmpDir,
|
||||
});
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
t.is(cachedVersions.length, shouldToolcacheBeBypassed ? 2 : 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
(0, ava_1.default)("download codeql bundle from github ae endpoint", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -13,7 +13,7 @@ import { GitHubApiDetails } from "./api-client";
|
|||
import * as codeql from "./codeql";
|
||||
import { AugmentationProperties, Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
|
||||
import { createFeatureFlags, FeatureFlag, FeatureFlags } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests, setupActionsVars } from "./testing-utils";
|
||||
|
|
@ -66,17 +66,19 @@ test.beforeEach(() => {
|
|||
});
|
||||
|
||||
async function mockApiAndSetupCodeQL({
|
||||
version,
|
||||
apiDetails,
|
||||
featureFlags,
|
||||
isPinned,
|
||||
tmpDir,
|
||||
toolsInput,
|
||||
apiDetails,
|
||||
version,
|
||||
}: {
|
||||
version: string;
|
||||
apiDetails?: GitHubApiDetails;
|
||||
featureFlags?: FeatureFlags;
|
||||
isPinned?: boolean;
|
||||
tmpDir: string;
|
||||
toolsInput?: { input?: string };
|
||||
apiDetails?: GitHubApiDetails;
|
||||
version: string;
|
||||
}) {
|
||||
const platform =
|
||||
process.platform === "win32"
|
||||
|
|
@ -105,7 +107,7 @@ async function mockApiAndSetupCodeQL({
|
|||
apiDetails ?? sampleApiDetails,
|
||||
tmpDir,
|
||||
util.GitHubVariant.DOTCOM,
|
||||
createFeatureFlags([]),
|
||||
featureFlags ?? createFeatureFlags([]),
|
||||
getRunnerLogger(true),
|
||||
false
|
||||
);
|
||||
|
|
@ -218,6 +220,57 @@ test('download codeql bundle cache with pinned different version cached if "late
|
|||
});
|
||||
});
|
||||
|
||||
const TOOLCACHE_BYPASS_TEST_CASES: Array<
|
||||
[boolean, string | undefined, boolean]
|
||||
> = [
|
||||
[true, undefined, true],
|
||||
[false, undefined, false],
|
||||
[
|
||||
true,
|
||||
"https://github.com/github/codeql-action/releases/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
false,
|
||||
],
|
||||
];
|
||||
|
||||
for (const [
|
||||
isFeatureFlagEnabled,
|
||||
toolsInput,
|
||||
shouldToolcacheBeBypassed,
|
||||
] of TOOLCACHE_BYPASS_TEST_CASES) {
|
||||
test(`download codeql bundle ${
|
||||
shouldToolcacheBeBypassed ? "bypasses" : "does not bypass"
|
||||
} toolcache when feature flag ${
|
||||
isFeatureFlagEnabled ? "enabled" : "disabled"
|
||||
} and tools: ${toolsInput} passed`, async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
|
||||
await mockApiAndSetupCodeQL({
|
||||
version: "codeql-bundle-20200601",
|
||||
apiDetails: sampleApiDetails,
|
||||
isPinned: true,
|
||||
tmpDir,
|
||||
});
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
|
||||
await mockApiAndSetupCodeQL({
|
||||
version: defaults.bundleVersion,
|
||||
apiDetails: sampleApiDetails,
|
||||
featureFlags: createFeatureFlags(
|
||||
isFeatureFlagEnabled ? [FeatureFlag.BypassToolcacheEnabled] : []
|
||||
),
|
||||
toolsInput: { input: toolsInput },
|
||||
tmpDir,
|
||||
});
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
|
||||
t.is(cachedVersions.length, shouldToolcacheBeBypassed ? 2 : 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test("download codeql bundle from github ae endpoint", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue