Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Oct 16, 2020
1 parent 1c2cf99 commit 1c402b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import osm = require('os');

import {getInputs} from '../src/context';

test('without username getInputs throws errors', async () => {
expect(() => {
getInputs();
}).toThrowError('Input required and not supplied: username');
});

test('without password getInputs throws errors', async () => {
process.env['INPUT_USERNAME'] = 'dbowie';
expect(() => {
getInputs();
}).toThrowError('Input required and not supplied: password');
});

test('with password getInputs does not error', async () => {
test('with password and username getInputs does not error', async () => {
process.env['INPUT_USERNAME'] = 'dbowie';
process.env['INPUT_PASSWORD'] = 'groundcontrol';
expect(() => {
getInputs();
Expand Down
21 changes: 19 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,32 @@ test('errors when not run on linux platform', async () => {
expect(coreSpy).toHaveBeenCalledWith('Only supported on linux platform');
});

test('errors without username', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');

const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');

await run();

expect(coreSpy).toHaveBeenCalledWith('Input required and not supplied: username');
});

test('errors without password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');

const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');

const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username;

await run();

expect(coreSpy).toHaveBeenCalledWith('Input required and not supplied: password');
});

test('successful with only password', async () => {
test('successful with username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');

Expand All @@ -37,14 +51,17 @@ test('successful with only password', async () => {
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(() => {});

const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username;

const password: string = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;

await run();

expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith('');
expect(dockerSpy).toHaveBeenCalledWith('', '', password);
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
});

test('calls docker login', async () => {
Expand Down

0 comments on commit 1c402b7

Please sign in to comment.