qualiteer/lib/jobs/job-builder.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-07-18 21:43:10 +00:00
const baseCommand = "node";
const suiteEntry = "tests/assets/suite/runner.js";
const buildCommon = (jobRequest) => {
2022-08-09 14:07:53 +00:00
const { isTriage, ignore, region, testNames } = jobRequest;
const command = [baseCommand, suiteEntry];
2022-07-18 21:43:10 +00:00
// Apply Common Flags
2022-08-09 17:59:36 +00:00
if (isTriage) command.push(`isTriage=${isTriage}`);
if (ignore && ignore.length > 0) console.log("Would ignore", ignore);
if (region) command.push(`region=${region}`);
2022-07-18 21:43:10 +00:00
// Return new request
return { ...jobRequest, command };
};
2022-08-09 14:07:53 +00:00
const buildManual = (jobReq) => {
2022-08-09 17:59:36 +00:00
const { command, testNames } = jobReq;
if (testNames.length > 1)
throw Error("Currently only 1 test can be selected!");
2022-07-18 21:43:10 +00:00
2022-08-09 14:07:53 +00:00
command.push(`test=${testNames[0]}`);
return { ...jobReq, command };
};
2022-07-18 21:43:10 +00:00
2022-08-09 14:07:53 +00:00
const buildTags = (jobReq) => {
2022-08-09 17:59:36 +00:00
const { command, tags, testNames } = jobReq;
if (testNames && testNames.length > 0) {
2022-08-09 14:07:53 +00:00
return console.log("Would run tags as manual");
}
2022-08-09 17:59:36 +00:00
const arg = Buffer.from(JSON.stringify(tags), "utf8").toString("base64");
2022-08-09 14:07:53 +00:00
command.push(`tags=${arg}`);
2022-08-09 17:59:36 +00:00
return { ...jobReq, command };
2022-07-18 21:43:10 +00:00
};
2022-08-09 14:07:53 +00:00
const buildPipeline = (jobReq, socketId) => {
const { command, pipeline } = jobReq;
2022-08-09 17:59:36 +00:00
const { __test: test } = pipeline;
if (!test) throw Error("__test is required for pipeline jobs!");
pipeline.dashboardSocketId = socketId;
const arg = Buffer.from(JSON.stringify(pipeline), "utf8").toString("base64");
command.push(`pipeline=${arg}`);
command.push(`test=${test}`);
2022-07-18 21:43:10 +00:00
return { ...jobReq, command };
};
export default function jobBuilder(jobRequest, id) {
const jobReq = buildCommon(jobRequest, id);
2022-08-09 17:59:36 +00:00
const { pipeline, testNames, tags } = jobReq;
if (pipeline) return buildPipeline(jobReq, id);
else if (tags) return buildTags(jobReq);
else if (testNames) return buildManual(jobReq); //TODO currently does nothing
2022-08-09 14:07:53 +00:00
else throw Error("At least 1 'pipeline or tags or testNames' is required! ");
2022-07-18 21:43:10 +00:00
}