Add test for CodeQL version appearing in log.
This commit is contained in:
parent
cff15d7117
commit
c92bbd4223
6 changed files with 80 additions and 48 deletions
45
lib/setup-codeql.test.js
generated
45
lib/setup-codeql.test.js
generated
|
|
@ -85,34 +85,45 @@ ava_1.default.beforeEach(() => {
|
|||
});
|
||||
});
|
||||
(0, ava_1.default)("getCodeQLSource correctly returns bundled CLI version when tools == linked", async (t) => {
|
||||
const loggedMessages = [];
|
||||
const logger = (0, testing_utils_1.getRecordingLogger)(loggedMessages);
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource("linked", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, logger);
|
||||
// Assert first that we got the right version of the CodeQL CLI,
|
||||
// and that we're sourcing it using the correct method for that.
|
||||
const source = await setupCodeql.getCodeQLSource("linked", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, (0, logging_1.getRunnerLogger)(true));
|
||||
t.is(source.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
t.is(source.sourceType, "download");
|
||||
// Ensure that we're adequately notifying the user of the version we're using.
|
||||
const expected_message = {
|
||||
type: "info",
|
||||
message: `Using CodeQL CLI version: ${testing_utils_1.LINKED_CLI_VERSION.cliVersion} from download.`,
|
||||
};
|
||||
loggedMessages.forEach((msg) => {
|
||||
console.log(msg.message);
|
||||
});
|
||||
t.assert(loggedMessages.includes(expected_message));
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("getCodeQLSource correctly returns bundled CLI version when tools == latest", async (t) => {
|
||||
const loggedMessages = [];
|
||||
const logger = (0, testing_utils_1.getRecordingLogger)(loggedMessages);
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource("latest", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, logger);
|
||||
const source = await setupCodeql.getCodeQLSource("latest", testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, util_1.GitHubVariant.DOTCOM, (0, logging_1.getRunnerLogger)(true));
|
||||
t.is(source.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
t.is(source.sourceType, "download");
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("setupCodeQLBundle logs the CodeQL CLI version being used", async (t) => {
|
||||
const loggedMessages = [];
|
||||
const logger = (0, testing_utils_1.getRecordingLogger)(loggedMessages);
|
||||
// Stub the downloadCodeQL function to prevent downloading artefacts
|
||||
// during testing from being called.
|
||||
sinon
|
||||
.stub(setupCodeql, "downloadCodeQL")
|
||||
.resolves({
|
||||
toolsVersion: testing_utils_1.LINKED_CLI_VERSION.cliVersion,
|
||||
codeqlFolder: "codeql",
|
||||
toolsDownloadDurationMs: 200,
|
||||
});
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
const result = await setupCodeql.setupCodeQLBundle("linked", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, "tmp/codeql_action_test/", util_1.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, logger);
|
||||
// Basic sanity check that the version we got back is indeed
|
||||
// the linked (default) CLI version.
|
||||
t.is(result.toolsVersion, testing_utils_1.LINKED_CLI_VERSION.cliVersion);
|
||||
const expected_message = {
|
||||
type: "info",
|
||||
message: `Using CodeQL CLI version ${testing_utils_1.LINKED_CLI_VERSION.cliVersion} from download.`,
|
||||
};
|
||||
// Ensure message logging CodeQL CLI version was present in user logs.
|
||||
t.assert(loggedMessages.some((msg) => msg.message === expected_message.message));
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=setup-codeql.test.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue