qualiteer/lib/jobs/job-builder.js

68 lines
2 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 pipelineMapping = [
{
id: 0,
pipeline: [{ name: "primary" }, { name: "secondary", delay: 5000 }],
},
];
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 14:07:53 +00:00
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) => {
const {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) => {
const {command, tags, testNames} = jobReq;
if(testNames && testNames.length > 0){
return console.log("Would run tags as manual");
}
const arg = Buffer.from(JSON.stringify(tags), "utf8").toString(
"base64"
);
command.push(`tags=${arg}`);
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;
const {__test: test} = pipeline;
if(!test) throw Error("__test is required for pipeline jobs!");
2022-08-09 04:29:10 +00:00
pipeline.dashboardSocketId = socketId;
2022-08-09 14:07:53 +00:00
const arg = Buffer.from(JSON.stringify(pipeline), "utf8").toString(
2022-08-09 04:29:10 +00:00
"base64"
);
2022-08-09 14:07:53 +00:00
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 14:07:53 +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
else throw Error("At least 1 'pipeline or tags or testNames' is required! ");
2022-07-18 21:43:10 +00:00
}