mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 07:06:56 +00:00
chore(test): organize tests a bit better (#7)
* chore(test): organize tests a bit better * add caching
This commit is contained in:
parent
3747195c5f
commit
38c189f087
12 changed files with 101 additions and 73 deletions
81
.github/workflows/build.yml
vendored
81
.github/workflows/build.yml
vendored
|
|
@ -1,44 +1,40 @@
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
|
||||||
vault:
|
|
||||||
image: vault:1.2.3
|
|
||||||
ports:
|
|
||||||
- 8200/tcp
|
|
||||||
env:
|
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
|
||||||
options: --cap-add=IPC_LOCK
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
- name: Use Node.js 10.x
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
- name: npm install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: npm build
|
- name: npm build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: npm run test
|
- name: npm run test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
- name: npm run test:integration
|
|
||||||
run: npm run test:integration
|
|
||||||
env:
|
|
||||||
VAULT_HOST: localhost
|
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
test-ent:
|
integration:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
services:
|
||||||
vault:
|
vaultBasic:
|
||||||
|
image: vault:1.2.3
|
||||||
|
ports:
|
||||||
|
- 8200/tcp
|
||||||
|
env:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
options: --cap-add=IPC_LOCK
|
||||||
|
vaultEnterprise:
|
||||||
image: hashicorp/vault-enterprise:1.3.0_ent
|
image: hashicorp/vault-enterprise:1.3.0_ent
|
||||||
ports:
|
ports:
|
||||||
- 8200/tcp
|
- 8200/tcp
|
||||||
|
|
@ -52,19 +48,28 @@ jobs:
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
- name: npm install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: npm build
|
- name: npm build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: npm run test
|
- name: npm run test:integration:basic
|
||||||
run: npm run test
|
run: npm run test:integration:basic
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
- name: npm run test:integration-ent
|
|
||||||
run: npm run test:integration-ent
|
|
||||||
env:
|
env:
|
||||||
VAULT_HOST: localhost
|
VAULT_HOST: localhost
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
VAULT_PORT: ${{ job.services.vaultBasic.ports[8200] }}
|
||||||
|
CI: true
|
||||||
|
- name: npm run test:integration:enterprise
|
||||||
|
run: npm run test:integration:enterprise
|
||||||
|
env:
|
||||||
|
VAULT_HOST: localhost
|
||||||
|
VAULT_PORT: ${{ job.services.vaultEnterprise.ports[8200] }}
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
e2e:
|
e2e:
|
||||||
|
|
@ -72,7 +77,7 @@ jobs:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
vault:
|
vault:
|
||||||
image: vault:1.2.3
|
image: vault:1.3.0
|
||||||
ports:
|
ports:
|
||||||
- 8200/tcp
|
- 8200/tcp
|
||||||
env:
|
env:
|
||||||
|
|
@ -85,12 +90,19 @@ jobs:
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
- name: npm install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: npm build
|
- name: npm build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: setup vault
|
- name: setup vault
|
||||||
run: node ./e2e/setup.js
|
run: node ./integrationTests/e2e/setup.js
|
||||||
env:
|
env:
|
||||||
VAULT_HOST: localhost
|
VAULT_HOST: localhost
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
||||||
|
|
@ -108,13 +120,20 @@ jobs:
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [test, e2e]
|
needs: [build, integration, e2e]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
- name: Use Node.js 10.x
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
- name: npm install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: release
|
- name: release
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
# Start vault server locally
|
# Start vault server locally for the purposes of integration tests.
|
||||||
# You can run integration tests against server by running
|
|
||||||
# `VAULT_HOST=localhost VAULT_PORT=8200 CI=true npm run test:integration-ent`
|
|
||||||
version: "3.0"
|
version: "3.0"
|
||||||
services:
|
services:
|
||||||
vault:
|
vault:
|
||||||
image: hashicorp/vault-enterprise:1.3.0_ent
|
image: vault:1.3.0
|
||||||
environment:
|
environment:
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
ports:
|
ports:
|
||||||
- 8200:8200
|
- 8200:8200
|
||||||
privileged: true
|
privileged: true
|
||||||
|
vault-enterprise:
|
||||||
|
image: hashicorp/vault-enterprise:1.3.0_ent
|
||||||
|
environment:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
ports:
|
||||||
|
- 8201:8201
|
||||||
|
privileged: true
|
||||||
|
|
@ -5,51 +5,52 @@ const core = require('@actions/core');
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const { when } = require('jest-when');
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
const { exportSecrets } = require('../action');
|
const { exportSecrets } = require('../../action');
|
||||||
|
|
||||||
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
|
|
||||||
describe('integration', () => {
|
describe('integration', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Verify Connection
|
// Verify Connection
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
await got(`${vaultUrl}/v1/secret/config`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
await got(`${vaultUrl}/v1/secret/data/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
secret: "SUPERSECRET",
|
secret: 'SUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
await got(`${vaultUrl}/v1/secret/data/nested/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
otherSecret: "OTHERSUPERSECRET",
|
otherSecret: 'OTHERSUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url')
|
||||||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
|
.mockReturnValue(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token')
|
||||||
|
|
@ -63,7 +64,7 @@ describe('integration', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
mockInput('test secret')
|
mockInput('test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|
@ -71,7 +72,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('re-map secret', async () => {
|
it('re-map secret', async () => {
|
||||||
mockInput('test secret | TEST_KEY')
|
mockInput('test secret | TEST_KEY');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('nested/test otherSecret')
|
mockInput('nested/test otherSecret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
4
integrationTests/e2e/README.md
Normal file
4
integrationTests/e2e/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# e2e tests
|
||||||
|
|
||||||
|
This test suite runs `vault-action` as a GitHub Action in the context of a live build, and then verifies that the appropriate environmental variables are set.
|
||||||
|
These tests are intended to mostly be very simple smoke tests to verify that the action is being compiled and run correctly in context.
|
||||||
|
|
@ -16,7 +16,7 @@ const got = require('got');
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
secret: "SUPERSECRET",
|
secret: 'SUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
|
|
@ -29,7 +29,7 @@ const got = require('got');
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
otherSecret: "OTHERSUPERSECRET",
|
otherSecret: 'OTHERSUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
|
|
@ -5,20 +5,21 @@ const core = require('@actions/core');
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const { when } = require('jest-when');
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
const { exportSecrets } = require('../action');
|
const { exportSecrets } = require('../../action');
|
||||||
|
|
||||||
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||||
|
|
||||||
describe('integration', () => {
|
describe('integration', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Verify Connection
|
// Verify Connection
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
await got(`${vaultUrl}/v1/secret/config`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create namespace
|
// Create namespace
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/sys/namespaces/ns1`, {
|
await got(`${vaultUrl}/v1/sys/namespaces/ns1`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
|
|
@ -27,17 +28,17 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enable secret engine
|
// Enable secret engine
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/sys/mounts/secret`, {
|
await got(`${vaultUrl}/v1/sys/mounts/secret`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
'X-Vault-Namespace': 'ns1',
|
'X-Vault-Namespace': 'ns1',
|
||||||
},
|
},
|
||||||
body: {"path":"secret","type":"kv","config":{},"options":{"version":2},"generate_signing_key":true},
|
body: { path: 'secret', type: 'kv', config: {}, options: { version: 2 }, generate_signing_key: true },
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
await got(`${vaultUrl}/v1/secret/data/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
|
|
@ -45,13 +46,13 @@ describe('integration', () => {
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
secret: "SUPERSECRET_IN_NAMESPACE",
|
secret: 'SUPERSECRET_IN_NAMESPACE',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
await got(`${vaultUrl}/v1/secret/data/nested/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
|
|
@ -59,21 +60,19 @@ describe('integration', () => {
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
otherSecret: "OTHERSUPERSECRET_IN_NAMESPACE",
|
otherSecret: 'OTHERSUPERSECRET_IN_NAMESPACE',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url')
|
||||||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
|
.mockReturnValue(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token')
|
||||||
|
|
@ -91,7 +90,7 @@ describe('integration', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
mockInput('test secret')
|
mockInput('test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|
@ -99,7 +98,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('re-map secret', async () => {
|
it('re-map secret', async () => {
|
||||||
mockInput('test secret | TEST_KEY')
|
mockInput('test secret | TEST_KEY');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|
@ -107,7 +106,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('nested/test otherSecret')
|
mockInput('nested/test otherSecret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integration/', '<rootDir>/e2e/','<rootDir>/integration-ent'],
|
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build index.js -o dist",
|
"build": "ncc build index.js -o dist",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:integration": "jest -c integration/jest.config.js",
|
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
||||||
"test:integration-ent": "jest -c integration-ent/jest.config.js",
|
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
||||||
"test:e2e": "jest -c e2e/jest.config.js"
|
"test:e2e": "jest -c integrationTests/e2e/jest.config.js"
|
||||||
},
|
},
|
||||||
"release": {
|
"release": {
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue