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); }