Update tests

This commit is contained in:
Jacob Wallraff
2022-12-16 10:58:09 -08:00
parent f10599820f
commit 9b8fd40344
3 changed files with 65 additions and 2 deletions
@@ -674,6 +674,33 @@ jobs:
}); });
}); });
describe("job context", () => {
it("job context is suggested within a job", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
container:
image: node:14.16
steps:
- run: echo \${{ job.| }}
`;
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
expect(result.map(x => x.label)).toContain("container");
expect(result.map(x => x.label)).toContain("services");
expect(result.map(x => x.label)).toContain("status");
});
it("job context is suggested within a job", async () => {
});
it("job context is suggested within a job", async () => {
});
});
it("context completion items include kind and insert text", async () => { it("context completion items include kind and insert text", async () => {
const input = ` const input = `
on: push on: push
@@ -14,7 +14,7 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
// Container // Container
const jobContainer = job.container; const jobContainer = job.container;
if (jobContainer && isMapping(jobContainer)) { if (jobContainer && isMapping(jobContainer)) {
let containerContext = createContainerContext(jobContainer, false); const containerContext = createContainerContext(jobContainer, false);
jobContext.add("container", containerContext); jobContext.add("container", containerContext);
} }
@@ -26,7 +26,7 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
if (!isMapping(service.value)) { if (!isMapping(service.value)) {
continue continue
} }
let serviceContext = createContainerContext(service.value, true); const serviceContext = createContainerContext(service.value, true);
servicesContext.add(service.key.toString(), serviceContext); servicesContext.add(service.key.toString(), serviceContext);
} }
jobContext.add("services", servicesContext); jobContext.add("services", servicesContext);
@@ -59,6 +59,10 @@ function createContainerContext(container: MappingToken, isServices: boolean): d
if (isServices && portParts.length === 2) { if (isServices && portParts.length === 2) {
ports.add(portParts[1], new data.StringData(portParts[0])); ports.add(portParts[1], new data.StringData(portParts[0]));
} }
else {
// If the port isn't a mapping, just use null
ports.add(portParts[0], new data.Null());
}
} }
containerContext.add(token.key.toString(), ports); containerContext.add(token.key.toString(), ports);
} }
@@ -283,6 +283,38 @@ jobs:
expect(result).toEqual([]); expect(result).toEqual([]);
}); });
it("job.services.<service_id>", async () => {
const input = `
on: push
jobs:
test:
runs-on: ubuntu-latest
container:
image: node:14.16
steps:
- run: echo \${{ job.container.tupperware }}
`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([
{
message: "Context access might be invalid: tupperware",
range: {
end: {
character: 49,
line: 9
},
start: {
character: 18,
line: 9
}
},
severity: DiagnosticSeverity.Warning
}
]);
});
}); });
describe("strategy context", () => { describe("strategy context", () => {