mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-04-08 13:10:05 +00:00
feat: fix unit and add e2e test
This commit is contained in:
parent
0b17727b1c
commit
33ba690ebb
8 changed files with 180 additions and 97 deletions
91
integration/integration.test.js
Normal file
91
integration/integration.test.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
jest.mock('@actions/core');
|
||||
const core = require('@actions/core');
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
|
||||
const { exportSecrets } = require('../action');
|
||||
|
||||
describe('integration', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
// Verify Connection
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: 3,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
|
||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
body: {
|
||||
data: {
|
||||
e: 4,
|
||||
f: 5,
|
||||
g: 6,
|
||||
},
|
||||
},
|
||||
json: true,
|
||||
});
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('vaultUrl')
|
||||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('vaultToken')
|
||||
.mockReturnValue('testtoken');
|
||||
});
|
||||
|
||||
function mockInput(key) {
|
||||
when(core.getInput)
|
||||
.calledWith('keys')
|
||||
.mockReturnValue(key);
|
||||
}
|
||||
|
||||
it('get simple secret', async () => {
|
||||
mockInput('test a')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('A', 1);
|
||||
});
|
||||
|
||||
it('re-map secret', async () => {
|
||||
mockInput('test a | TEST_KEY')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('TEST_KEY', 1);
|
||||
});
|
||||
|
||||
it('get nested secret', async () => {
|
||||
mockInput('nested/test e')
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportSecret).toBeCalledWith('E', 4);
|
||||
});
|
||||
});
|
||||
3
integration/jest.config.js
Normal file
3
integration/jest.config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
verbose: true
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue