From d48adfa651eb312dc882b1446bfc578e745d5036 Mon Sep 17 00:00:00 2001 From: Jacob Wallraff Date: Mon, 12 Dec 2022 15:10:28 -0800 Subject: [PATCH] Add tests and use null context --- .../src/context-providers/job.ts | 53 +++++++--------- .../src/validate.expressions.test.ts | 61 +++++++++++++++++++ 2 files changed, 83 insertions(+), 31 deletions(-) diff --git a/actions-languageservice/src/context-providers/job.ts b/actions-languageservice/src/context-providers/job.ts index 1ecb46f..3353be8 100644 --- a/actions-languageservice/src/context-providers/job.ts +++ b/actions-languageservice/src/context-providers/job.ts @@ -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; } } diff --git a/actions-languageservice/src/validate.expressions.test.ts b/actions-languageservice/src/validate.expressions.test.ts index b914ec9..58b6597 100644 --- a/actions-languageservice/src/validate.expressions.test.ts +++ b/actions-languageservice/src/validate.expressions.test.ts @@ -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.", 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 = `