From 535709808465b7554568b9186d222a926971d805 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Thu, 20 Feb 2020 11:23:41 -0600 Subject: [PATCH] fix(tests): fix unit tests and improve e2e --- .github/workflows/build.yml | 3 +++ action.test.js | 21 +++++++++++++++------ integrationTests/e2e/e2e.test.js | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9938ba8..8d8b5de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -112,6 +112,7 @@ jobs: VAULT_PORT: ${{ job.services.vault.ports[8200] }} - name: use vault action (default K/V version 2) uses: ./ + id: kv-secrets with: url: http://localhost:${{ job.services.vault.ports[8200] }} token: testtoken @@ -140,6 +141,8 @@ jobs: /cubbyhole/test zip | NAMED_CUBBYSECRET ; - name: verify run: npm run test:e2e + env: + OTHER_SECRET_OUTPUT: ${{ job.kv-secrets.outputs.otherSecret }} publish: if: github.event_name == 'push' && contains(github.ref, 'master') diff --git a/action.test.js b/action.test.js index b53d08a..d1af937 100644 --- a/action.test.js +++ b/action.test.js @@ -18,7 +18,8 @@ describe('parseSecretsInput', () => { expect(output).toContainEqual({ secretPath: 'test', secretSelector: 'key', - outputName: 'KEY', + outputVarName: 'key', + envVarName: 'KEY', isJSONPath: false }); }); @@ -27,7 +28,8 @@ describe('parseSecretsInput', () => { const output = parseSecretsInput('test key|testName'); expect(output).toHaveLength(1); expect(output[0]).toMatchObject({ - outputName: 'testName', + outputVarName: 'testName', + envVarName: 'testName', }); }); @@ -58,10 +60,12 @@ describe('parseSecretsInput', () => { expect(output).toHaveLength(2); expect(output[0]).toMatchObject({ - outputName: 'A', + outputVarName: 'a', + envVarName: 'A', }); expect(output[1]).toMatchObject({ - outputName: 'secondName', + outputVarName: 'secondName', + envVarName: 'secondName' }); }); @@ -76,10 +80,12 @@ describe('parseSecretsInput', () => { secretPath: 'first', }); expect(output[1]).toMatchObject({ - outputName: 'B', + outputVarName: 'b', + envVarName: 'B' }); expect(output[2]).toMatchObject({ - outputName: 'SOME_C', + outputVarName: 'SOME_C', + envVarName: 'SOME_C', }); }) }); @@ -172,6 +178,7 @@ describe('exportSecrets', () => { await exportSecrets(); expect(core.exportVariable).toBeCalledWith('KEY', '1'); + expect(core.setOutput).toBeCalledWith('key', '1'); }); it('mapped secret retrieval', async () => { @@ -183,6 +190,7 @@ describe('exportSecrets', () => { await exportSecrets(); expect(core.exportVariable).toBeCalledWith('TEST_NAME', '1'); + expect(core.setOutput).toBeCalledWith('TEST_NAME', '1'); }); it('simple secret retrieval from K/V v1', async () => { @@ -197,5 +205,6 @@ describe('exportSecrets', () => { await exportSecrets(); expect(core.exportVariable).toBeCalledWith('KEY', '1'); + expect(core.setOutput).toBeCalledWith('key', '1'); }); }); diff --git a/integrationTests/e2e/e2e.test.js b/integrationTests/e2e/e2e.test.js index 56421ba..c5ed5af 100644 --- a/integrationTests/e2e/e2e.test.js +++ b/integrationTests/e2e/e2e.test.js @@ -3,6 +3,7 @@ describe('e2e', () => { expect(process.env.SECRET).toBe("SUPERSECRET"); expect(process.env.NAMED_SECRET).toBe("SUPERSECRET"); expect(process.env.OTHERSECRET).toBe("OTHERSUPERSECRET"); + expect(process.env.OTHER_SECRET_OUTPUT).toBe("OTHERSUPERSECRET"); expect(process.env.ALTSECRET).toBe("CUSTOMSECRET"); expect(process.env.NAMED_ALTSECRET).toBe("CUSTOMSECRET"); expect(process.env.OTHERALTSECRET).toBe("OTHERCUSTOMSECRET");