Skip to content

Commit c92bbd4

Browse files
committed
Add test for CodeQL version appearing in log.
1 parent cff15d7 commit c92bbd4

File tree

6 files changed

+80
-48
lines changed

6 files changed

+80
-48
lines changed

lib/setup-codeql.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js

Lines changed: 28 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.test.ts

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,53 +98,72 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
9898
});
9999

100100
test("getCodeQLSource correctly returns bundled CLI version when tools == linked", async (t) => {
101-
const loggedMessages: LoggedMessage[] = [];
102-
const logger = getRecordingLogger(loggedMessages);
103-
104101
await withTmpDir(async (tmpDir) => {
105102
setupActionsVars(tmpDir, tmpDir);
106103
const source = await setupCodeql.getCodeQLSource(
107104
"linked",
108105
SAMPLE_DEFAULT_CLI_VERSION,
109106
SAMPLE_DOTCOM_API_DETAILS,
110107
GitHubVariant.DOTCOM,
111-
logger,
108+
getRunnerLogger(true),
112109
);
113110

114-
// Assert first that we got the right version of the CodeQL CLI,
115-
// and that we're sourcing it using the correct method for that.
116111
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
117112
t.is(source.sourceType, "download");
118-
119-
// Ensure that we're adequately notifying the user of the version we're using.
120-
const expected_message: LoggedMessage = {
121-
type: "info",
122-
message: `Using CodeQL CLI version: ${LINKED_CLI_VERSION.cliVersion} from download.`,
123-
};
124-
125-
loggedMessages.forEach((msg) => {
126-
console.log(msg.message);
127-
});
128-
129-
t.assert(loggedMessages.includes(expected_message));
130113
});
131114
});
132115

133116
test("getCodeQLSource correctly returns bundled CLI version when tools == latest", async (t) => {
134-
const loggedMessages = [];
135-
const logger = getRecordingLogger(loggedMessages);
136-
137117
await withTmpDir(async (tmpDir) => {
138118
setupActionsVars(tmpDir, tmpDir);
139119
const source = await setupCodeql.getCodeQLSource(
140120
"latest",
141121
SAMPLE_DEFAULT_CLI_VERSION,
142122
SAMPLE_DOTCOM_API_DETAILS,
143123
GitHubVariant.DOTCOM,
144-
logger,
124+
getRunnerLogger(true),
145125
);
146126

147127
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
148128
t.is(source.sourceType, "download");
149129
});
150130
});
131+
132+
test("setupCodeQLBundle logs the CodeQL CLI version being used", async (t) => {
133+
const loggedMessages: LoggedMessage[] = [];
134+
const logger = getRecordingLogger(loggedMessages);
135+
136+
// Stub the downloadCodeQL function to prevent downloading artefacts
137+
// during testing from being called.
138+
sinon.stub(setupCodeql, "downloadCodeQL").resolves({
139+
toolsVersion: LINKED_CLI_VERSION.cliVersion,
140+
codeqlFolder: "codeql",
141+
toolsDownloadDurationMs: 200,
142+
});
143+
144+
await withTmpDir(async (tmpDir) => {
145+
setupActionsVars(tmpDir, tmpDir);
146+
const result = await setupCodeql.setupCodeQLBundle(
147+
"linked",
148+
SAMPLE_DOTCOM_API_DETAILS,
149+
"tmp/codeql_action_test/",
150+
GitHubVariant.DOTCOM,
151+
SAMPLE_DEFAULT_CLI_VERSION,
152+
logger,
153+
);
154+
155+
// Basic sanity check that the version we got back is indeed
156+
// the linked (default) CLI version.
157+
t.is(result.toolsVersion, LINKED_CLI_VERSION.cliVersion);
158+
159+
const expected_message: LoggedMessage = {
160+
type: "info",
161+
message: `Using CodeQL CLI version ${LINKED_CLI_VERSION.cliVersion} from download.`,
162+
};
163+
164+
// Ensure message logging CodeQL CLI version was present in user logs.
165+
t.assert(
166+
loggedMessages.some((msg) => msg.message === expected_message.message),
167+
);
168+
});
169+
});

src/setup-codeql.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export async function tryGetFallbackToolcacheVersion(
493493
return fallbackVersion;
494494
}
495495

496-
export async function downloadCodeQL(
496+
export const downloadCodeQL = async function (
497497
codeqlURL: string,
498498
maybeBundleVersion: string | undefined,
499499
maybeCliVersion: string | undefined,
@@ -614,7 +614,7 @@ export async function downloadCodeQL(
614614
codeqlFolder: toolcachedBundlePath,
615615
toolsDownloadDurationMs,
616616
};
617-
}
617+
};
618618

619619
export function getCodeQLURLVersion(url: string): string {
620620
const match = url.match(/\/codeql-bundle-(.*)\//);
@@ -692,7 +692,9 @@ export async function setupCodeQLBundle(
692692
logger,
693693
);
694694

695-
logger.info("Using CodeQL CLI version " + source.toolsVersion + " from " + source.sourceType + ".");
695+
logger.info(
696+
`Using CodeQL CLI version ${source.toolsVersion} from ${source.sourceType}.`,
697+
);
696698

697699
let codeqlFolder: string;
698700
let toolsVersion = source.toolsVersion;

0 commit comments

Comments
 (0)