Add tests and use null context

This commit is contained in:
Jacob Wallraff
2022-12-12 15:10:28 -08:00
parent 8c74ec1c05
commit d48adfa651
2 changed files with 83 additions and 31 deletions
@@ -16,45 +16,36 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
}
const jobContext = new data.Dictionary();
for (const pair of job) {
if (!isString(pair.key)) {
continue;
}
if (!keys.includes(pair.key.value)) {
continue;
}
const value = isScalar(pair.value) ? scalarToData(pair.value) : new data.Null();
jobContext.add(pair.key.value, value);
}
for (const key of keys) {
if (!jobContext.get(key)) {
switch (key) {
case "container":
var containerDictionary = new data.Dictionary();
for (const containerKey of containerKeys) {
if (job.container[containerKey]) {
containerDictionary.add(containerKey, job.container[containerKey]);
}
}
jobContext.add(key, containerDictionary);
// var containerDictionary = new data.Dictionary();
// for (const containerKey of containerKeys) {
// if (job.container[containerKey]) {
// containerDictionary.add(containerKey, job.container[containerKey]);
// }
// }
// jobContext.add(key, containerDictionary);
jobContext.add(key, new data.Null());
break;
case "services":
var services = new data.Dictionary();
for (const service of job.services) {
var serviceDictionary = new data.Dictionary();
for (const serviceKey of serviceKeys) {
if (service[serviceKey]) {
serviceDictionary.add(serviceKey, service[serviceKey]);
}
}
services.add(service, serviceDictionary);
}
jobContext.add(key, services);
// var services = new data.Dictionary();
// for (const service of job.services) {
// var serviceDictionary = new data.Dictionary();
// for (const serviceKey of serviceKeys) {
// if (service[serviceKey]) {
// serviceDictionary.add(serviceKey, service[serviceKey]);
// }
// }
// services.add(service, serviceDictionary);
// }
// jobContext.add(key, services);
jobContext.add(key, new data.Null());
break;
case "status":
jobContext.add(key, job.status);
// jobContext.add(key, job.status);
jobContext.add(key, new data.Null());
break;
}
}
@@ -224,6 +224,67 @@ jobs:
});
});
describe("job context", () => {
it("job.status", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo \${{ job.status }}
`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([]);
});
it("job.container", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
container:
image: node:14.16
env:
NODE_ENV: development
ports:
- 80
volumes:
- my_docker_volume:/volume_mount
options: --cpus 1
steps:
- run: echo \${{ job.container }}
`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([]);
});
it("job.services.<service_id>", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
services:
nginx:
image: nginx
ports:
- 8080:80
steps:
- run: echo \${{ job.services.nginx }}
`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([]);
});
});
describe("strategy context", () => {
it("reference within a matrix job", async () => {
const input = `