feat: simplify input parameters and docs

This commit is contained in:
Richard Simpson
2019-09-20 17:56:08 -05:00
parent 9c32e02d93
commit 19c0b21a1d
6 changed files with 80 additions and 80 deletions

View File

@@ -6,23 +6,23 @@ const core = require('@actions/core');
const got = require('got');
const {
exportSecrets,
parseKeysInput,
parseSecretsInput,
} = require('./action');
const { when } = require('jest-when');
describe('parseKeysInput', () => {
it('parses simple key', () => {
const output = parseKeysInput('test key');
describe('parseSecretsInput', () => {
it('parses simple secret', () => {
const output = parseSecretsInput('test key');
expect(output).toContainEqual({
keyPath: 'test',
dataKey: 'key',
secretPath: 'test',
secretKey: 'key',
outputName: 'KEY',
});
});
it('parses mapped key', () => {
const output = parseKeysInput('test key|testName');
it('parses mapped secret', () => {
const output = parseSecretsInput('test key|testName');
expect(output).toHaveLength(1);
expect(output[0]).toMatchObject({
outputName: 'testName',
@@ -30,29 +30,29 @@ describe('parseKeysInput', () => {
});
it('fails on invalid mapped name', () => {
expect(() => parseKeysInput('test key|'))
expect(() => parseSecretsInput('test key|'))
.toThrowError(`You must provide a value when mapping a secret to a name. Input: "test key|"`)
});
it('fails on invalid path for mapped', () => {
expect(() => parseKeysInput('|testName'))
expect(() => parseSecretsInput('|testName'))
.toThrowError(`You must provide a valid path and key. Input: "|testName"`)
});
it('parses multiple keys', () => {
const output = parseKeysInput('first a;second b;');
it('parses multiple secrets', () => {
const output = parseSecretsInput('first a;second b;');
expect(output).toHaveLength(2);
expect(output[0]).toMatchObject({
keyPath: 'first',
secretPath: 'first',
});
expect(output[1]).toMatchObject({
keyPath: 'second',
secretPath: 'second',
});
});
it('parses multiple complex keys', () => {
const output = parseKeysInput('first a;second b|secondName');
it('parses multiple complex secret input', () => {
const output = parseSecretsInput('first a;second b|secondName');
expect(output).toHaveLength(2);
expect(output[0]).toMatchObject({
@@ -64,14 +64,14 @@ describe('parseKeysInput', () => {
});
it('parses multiline input', () => {
const output = parseKeysInput(`
const output = parseSecretsInput(`
first a;
second b;
third c | SOME_C;`);
expect(output).toHaveLength(3);
expect(output[0]).toMatchObject({
keyPath: 'first',
secretPath: 'first',
});
expect(output[1]).toMatchObject({
outputName: 'B',
@@ -88,17 +88,17 @@ describe('exportSecrets', () => {
jest.resetAllMocks();
when(core.getInput)
.calledWith('vaultUrl')
.calledWith('url')
.mockReturnValue('http://vault:8200');
when(core.getInput)
.calledWith('vaultToken')
.calledWith('token')
.mockReturnValue('EXAMPLE');
});
function mockInput(key) {
when(core.getInput)
.calledWith('keys')
.calledWith('secrets')
.mockReturnValue(key);
}
@@ -112,7 +112,7 @@ describe('exportSecrets', () => {
});
}
it('simple key retrieval', async () => {
it('simple secret retrieval', async () => {
mockInput('test key');
mockVaultData({
key: 1
@@ -123,7 +123,7 @@ describe('exportSecrets', () => {
expect(core.exportVariable).toBeCalledWith('KEY', '1');
});
it('mapped key retrieval', async () => {
it('mapped secret retrieval', async () => {
mockInput('test key|TEST_NAME');
mockVaultData({
key: 1