Skip to content

Commit 725ed41

Browse files
committed
Add tests for shouldShowCombineSarifFilesDeprecationWarning
1 parent 1de9b37 commit 725ed41

File tree

6 files changed

+157
-9
lines changed

6 files changed

+157
-9
lines changed

lib/upload-lib.js

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

lib/upload-lib.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/upload-lib.test.js

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

lib/upload-lib.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/upload-lib.test.ts

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import * as path from "path";
33

44
import test from "ava";
55

6+
import { Feature } from "./feature-flags";
67
import { getRunnerLogger, Logger } from "./logging";
7-
import { setupTests } from "./testing-utils";
8+
import { createFeatures, setupTests } from "./testing-utils";
89
import * as uploadLib from "./upload-lib";
9-
import { initializeEnvironment, withTmpDir } from "./util";
10+
import { GitHubVariant, initializeEnvironment, withTmpDir } from "./util";
1011

1112
setupTests(test);
1213

@@ -324,6 +325,106 @@ test("accept results with invalid artifactLocation.uri value", (t) => {
324325
);
325326
});
326327

328+
test("shouldShowCombineSarifFilesDeprecationWarning when on dotcom with feature flag", async (t) => {
329+
t.true(
330+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
331+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
332+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
333+
{
334+
type: GitHubVariant.DOTCOM,
335+
},
336+
),
337+
);
338+
});
339+
340+
test("shouldShowCombineSarifFilesDeprecationWarning without feature flag", async (t) => {
341+
t.false(
342+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
343+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
344+
createFeatures([]),
345+
{
346+
type: GitHubVariant.DOTCOM,
347+
},
348+
),
349+
);
350+
});
351+
352+
test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.13", async (t) => {
353+
t.false(
354+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
355+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
356+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
357+
{
358+
type: GitHubVariant.GHES,
359+
version: "3.13.2",
360+
},
361+
),
362+
);
363+
});
364+
365+
test("shouldShowCombineSarifFilesDeprecationWarning when on GHES 3.14", async (t) => {
366+
t.true(
367+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
368+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
369+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
370+
{
371+
type: GitHubVariant.GHES,
372+
version: "3.14.0",
373+
},
374+
),
375+
);
376+
});
377+
378+
test("shouldShowCombineSarifFilesDeprecationWarning with only 1 run", async (t) => {
379+
t.false(
380+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
381+
[createMockSarif("abc", "def")],
382+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
383+
{
384+
type: GitHubVariant.DOTCOM,
385+
},
386+
),
387+
);
388+
});
389+
390+
test("shouldShowCombineSarifFilesDeprecationWarning with distinct categories", async (t) => {
391+
t.false(
392+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
393+
[createMockSarif("abc", "def"), createMockSarif("def", "def")],
394+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
395+
{
396+
type: GitHubVariant.DOTCOM,
397+
},
398+
),
399+
);
400+
});
401+
402+
test("shouldShowCombineSarifFilesDeprecationWarning with distinct tools", async (t) => {
403+
t.false(
404+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
405+
[createMockSarif("abc", "abc"), createMockSarif("abc", "def")],
406+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
407+
{
408+
type: GitHubVariant.DOTCOM,
409+
},
410+
),
411+
);
412+
});
413+
414+
test("shouldShowCombineSarifFilesDeprecationWarning when environment variable is already set", async (t) => {
415+
process.env["CODEQL_MERGE_SARIF_DEPRECATION_WARNING"] = "true";
416+
417+
t.false(
418+
await uploadLib.shouldShowCombineSarifFilesDeprecationWarning(
419+
[createMockSarif("abc", "def"), createMockSarif("abc", "def")],
420+
createFeatures([Feature.CombineSarifFilesDeprecationWarning]),
421+
{
422+
type: GitHubVariant.DOTCOM,
423+
},
424+
),
425+
);
426+
});
427+
327428
function createMockSarif(id?: string, tool?: string) {
328429
return {
329430
runs: [

src/upload-lib.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getGitHubVersion, wrapApiConfigurationError } from "./api-client";
1515
import { CodeQL, getCodeQL } from "./codeql";
1616
import { getConfig } from "./config-utils";
1717
import { EnvVar } from "./environment";
18-
import { Feature, Features } from "./feature-flags";
18+
import { Feature, FeatureEnablement, Features } from "./feature-flags";
1919
import * as fingerprints from "./fingerprints";
2020
import { initCodeQL } from "./init";
2121
import { Logger } from "./logging";
@@ -122,9 +122,10 @@ function areAllRunsUnique(sarifObjects: SarifFile[]): boolean {
122122
return true;
123123
}
124124

125-
async function shouldShowCombineSarifFilesDeprecationWarning(
125+
// Checks whether the deprecation warning for combining SARIF files should be shown.
126+
export async function shouldShowCombineSarifFilesDeprecationWarning(
126127
sarifObjects: util.SarifFile[],
127-
features: Features,
128+
features: FeatureEnablement,
128129
githubVersion: GitHubVersion,
129130
) {
130131
if (!(await features.getValue(Feature.CombineSarifFilesDeprecationWarning))) {
@@ -153,7 +154,7 @@ async function shouldShowCombineSarifFilesDeprecationWarning(
153154
async function combineSarifFilesUsingCLI(
154155
sarifFiles: string[],
155156
gitHubVersion: GitHubVersion,
156-
features: Features,
157+
features: FeatureEnablement,
157158
logger: Logger,
158159
): Promise<SarifFile> {
159160
logger.info("Combining SARIF files using the CodeQL CLI");

0 commit comments

Comments
 (0)