5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-09 08:06:55 +00:00

chore(test): organize tests a bit better

This commit is contained in:
Richard Simpson 2019-11-24 15:39:33 -06:00
parent 3747195c5f
commit 16e4be0a47
12 changed files with 66 additions and 57 deletions

View file

@ -1,7 +1,7 @@
on: [push]
jobs:
test:
integration-basic:
runs-on: ubuntu-latest
services:
@ -27,14 +27,14 @@ jobs:
run: npm run test
env:
CI: true
- name: npm run test:integration
run: npm run test:integration
- name: npm run test:integration:basic
run: npm run test:integration:basic
env:
VAULT_HOST: localhost
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
CI: true
test-ent:
integration-enterprise:
runs-on: ubuntu-latest
services:
@ -60,8 +60,8 @@ jobs:
run: npm run test
env:
CI: true
- name: npm run test:integration-ent
run: npm run test:integration-ent
- name: npm run test:integration:enterprise
run: npm run test:integration:enterprise
env:
VAULT_HOST: localhost
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
@ -72,7 +72,7 @@ jobs:
services:
vault:
image: vault:1.2.3
image: vault:1.3.0
ports:
- 8200/tcp
env:
@ -108,7 +108,7 @@ jobs:
publish:
runs-on: ubuntu-latest
needs: [test, e2e]
needs: [integration-basic, integration-enterprise, e2e]
steps:
- uses: actions/checkout@v1
- name: Use Node.js 10.x

View file

@ -1,12 +1,17 @@
# Start vault server locally
# You can run integration tests against server by running
# `VAULT_HOST=localhost VAULT_PORT=8200 CI=true npm run test:integration-ent`
# Start vault server locally for the purposes of integration tests.
version: "3.0"
services:
vault:
image: hashicorp/vault-enterprise:1.3.0_ent
image: vault:1.3.0
environment:
VAULT_DEV_ROOT_TOKEN_ID: testtoken
ports:
- 8200:8200
privileged: true
vault-enterprise:
image: hashicorp/vault-enterprise:1.3.0_ent
environment:
VAULT_DEV_ROOT_TOKEN_ID: testtoken
ports:
- 8201:8201
privileged: true

View file

@ -1,55 +1,56 @@
jest.mock('@actions/core');
jest.mock('@actions/core/lib/command');
const core = require('@actions/core');
const core = require('./@actions/core');
const got = require('got');
const { when } = require('jest-when');
const got = require('./got');
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', () => {
beforeAll(async () => {
// Verify Connection
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
await got(`${vaultUrl}/v1/secret/config`, {
headers: {
'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',
headers: {
'X-Vault-Token': 'testtoken',
},
body: {
data: {
secret: "SUPERSECRET",
secret: 'SUPERSECRET',
},
},
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',
headers: {
'X-Vault-Token': 'testtoken',
},
body: {
data: {
otherSecret: "OTHERSUPERSECRET",
otherSecret: 'OTHERSUPERSECRET',
},
},
json: true,
});
})
});
beforeEach(() => {
jest.resetAllMocks();
when(core.getInput)
.calledWith('url')
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
.mockReturnValue(`${vaultUrl}`);
when(core.getInput)
.calledWith('token')
@ -63,7 +64,7 @@ describe('integration', () => {
}
it('get simple secret', async () => {
mockInput('test secret')
mockInput('test secret');
await exportSecrets();
@ -71,7 +72,7 @@ describe('integration', () => {
});
it('re-map secret', async () => {
mockInput('test secret | TEST_KEY')
mockInput('test secret | TEST_KEY');
await exportSecrets();
@ -79,7 +80,7 @@ describe('integration', () => {
});
it('get nested secret', async () => {
mockInput('nested/test otherSecret')
mockInput('nested/test otherSecret');
await exportSecrets();

View 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.

View file

@ -1,4 +1,4 @@
const got = require('got');
const got = require('./got');
(async () => {
try {
@ -16,7 +16,7 @@ const got = require('got');
},
body: {
data: {
secret: "SUPERSECRET",
secret: 'SUPERSECRET',
},
},
json: true,
@ -29,7 +29,7 @@ const got = require('got');
},
body: {
data: {
otherSecret: "OTHERSUPERSECRET",
otherSecret: 'OTHERSUPERSECRET',
},
},
json: true,

View file

@ -1,24 +1,25 @@
jest.mock('@actions/core');
jest.mock('@actions/core/lib/command');
const core = require('@actions/core');
const core = require('./@actions/core');
const got = require('got');
const { when } = require('jest-when');
const got = require('./got');
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', () => {
beforeAll(async () => {
// Verify Connection
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
await got(`${vaultUrl}/v1/secret/config`, {
headers: {
'X-Vault-Token': 'testtoken',
},
});
// 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',
headers: {
'X-Vault-Token': 'testtoken',
@ -27,17 +28,17 @@ describe('integration', () => {
});
// 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',
headers: {
'X-Vault-Token': 'testtoken',
'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,
});
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
await got(`${vaultUrl}/v1/secret/data/test`, {
method: 'POST',
headers: {
'X-Vault-Token': 'testtoken',
@ -45,13 +46,13 @@ describe('integration', () => {
},
body: {
data: {
secret: "SUPERSECRET_IN_NAMESPACE",
secret: 'SUPERSECRET_IN_NAMESPACE',
},
},
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',
headers: {
'X-Vault-Token': 'testtoken',
@ -59,21 +60,19 @@ describe('integration', () => {
},
body: {
data: {
otherSecret: "OTHERSUPERSECRET_IN_NAMESPACE",
otherSecret: 'OTHERSUPERSECRET_IN_NAMESPACE',
},
},
json: true,
});
});
})
beforeEach(() => {
jest.resetAllMocks();
when(core.getInput)
.calledWith('url')
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
.mockReturnValue(`${vaultUrl}`);
when(core.getInput)
.calledWith('token')
@ -91,7 +90,7 @@ describe('integration', () => {
}
it('get simple secret', async () => {
mockInput('test secret')
mockInput('test secret');
await exportSecrets();
@ -99,7 +98,7 @@ describe('integration', () => {
});
it('re-map secret', async () => {
mockInput('test secret | TEST_KEY')
mockInput('test secret | TEST_KEY');
await exportSecrets();
@ -107,7 +106,7 @@ describe('integration', () => {
});
it('get nested secret', async () => {
mockInput('nested/test otherSecret')
mockInput('nested/test otherSecret');
await exportSecrets();

View file

@ -1,3 +1,3 @@
module.exports = {
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integration/', '<rootDir>/e2e/','<rootDir>/integration-ent'],
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
};

View file

@ -6,9 +6,9 @@
"scripts": {
"build": "ncc build index.js -o dist",
"test": "jest",
"test:integration": "jest -c integration/jest.config.js",
"test:integration-ent": "jest -c integration-ent/jest.config.js",
"test:e2e": "jest -c e2e/jest.config.js"
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
"test:e2e": "jest -c integrationTests/e2e/jest.config.js"
},
"release": {
"branch": "master",