From f3c2e45637c0ec26bc53c7ceeafc5c5109d69a0e Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Wed, 7 Oct 2020 22:31:05 -0700 Subject: [PATCH] Add context tests --- __tests__/context.test.ts | 16 ++++++++++++++++ src/context.ts | 2 +- src/main.ts | 8 ++++---- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 __tests__/context.test.ts diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts new file mode 100644 index 0000000..a77f44b --- /dev/null +++ b/__tests__/context.test.ts @@ -0,0 +1,16 @@ +import osm = require('os'); + +import {getInputs} from '../src/context'; + +test('without password getInputs throws errors', async () => { + expect(() => { + getInputs(); + }).toThrowError('Input required and not supplied: password'); +}); + +test('with password getInputs does not error', async () => { + process.env['INPUT_PASSWORD'] = 'groundcontrol'; + expect(() => { + getInputs(); + }).not.toThrowError(); +}); diff --git a/src/context.ts b/src/context.ts index b284b90..3d24754 100644 --- a/src/context.ts +++ b/src/context.ts @@ -7,7 +7,7 @@ export interface Inputs { logout: string; } -export async function getInputs(): Promise { +export function getInputs(): Inputs { return { registry: core.getInput('registry'), username: core.getInput('username'), diff --git a/src/main.ts b/src/main.ts index 4f377b4..a62adf8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,10 +11,10 @@ async function run(): Promise { return; } - let inputs: Inputs = await getInputs(); - stateHelper.setRegistry(inputs.registry); - stateHelper.setLogout(inputs.logout); - await docker.login(inputs.registry, inputs.username, inputs.password); + const {registry, username, password, logout} = getInputs(); + stateHelper.setRegistry(registry); + stateHelper.setLogout(logout); + await docker.login(registry, username, password); } catch (error) { core.setFailed(error.message); }