forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.test.ts
61 lines (48 loc) · 2.48 KB
/
pipeline.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { beforeEach, describe, expect, test } from "bun:test";
import { generatePipelines } from "./pipeline";
import { setBwcVersionsPath, setSnapshotBwcVersionsPath } from "./bwc-versions";
describe("generatePipelines", () => {
beforeEach(() => {
setBwcVersionsPath(`${import.meta.dir}/mocks/bwcVersions`);
setSnapshotBwcVersionsPath(`${import.meta.dir}/mocks/snapshotBwcVersions`);
process.env["GITHUB_PR_LABELS"] = "test-label-1,test-label-2";
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "";
});
// Helper for testing pipeline generations that should be the same when using the overall ci trigger comment "buildkite test this"
const testWithTriggerCheck = (directory: string, changedFiles?: string[], comment = "buildkite test this") => {
const pipelines = generatePipelines(directory, changedFiles);
expect(pipelines).toMatchSnapshot();
process.env["GITHUB_PR_TRIGGER_COMMENT"] = comment;
const pipelinesWithTriggerComment = generatePipelines(directory, changedFiles);
expect(pipelinesWithTriggerComment).toEqual(pipelines);
};
test("should generate correct pipelines with a non-docs change", () => {
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle", "docs/README.asciidoc"]);
});
test("should generate correct pipelines with only docs changes", () => {
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["docs/README.asciidoc"]);
});
test("should generate correct pipelines with full BWC expansion", () => {
process.env["GITHUB_PR_LABELS"] = "test-full-bwc";
testWithTriggerCheck(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
});
test("should generate correct pipeline when using a trigger comment for it", () => {
process.env["GITHUB_PR_TRIGGER_COMMENT"] = "run elasticsearch-ci/using-defaults";
const pipelines = generatePipelines(`${import.meta.dir}/mocks/pipelines`, ["build.gradle"]);
expect(pipelines).toMatchSnapshot();
});
test("should generate correct pipelines with a non-docs change and @elasticmachine", () => {
testWithTriggerCheck(
`${import.meta.dir}/mocks/pipelines`,
["build.gradle", "docs/README.asciidoc"],
"@elasticmachine test this please"
);
});
test("should generate correct pipelines with a non-docs change and @elasticsearchmachine", () => {
testWithTriggerCheck(
`${import.meta.dir}/mocks/pipelines`,
["build.gradle", "docs/README.asciidoc"],
"@elasticsearchmachine test this please"
);
});
});