3
0
Fork 0
mirror of https://gitea.com/docker/login-action.git synced 2024-11-26 03:19:37 +01:00

Fix tests

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-10-16 18:34:48 +02:00
parent 1c2cf9942d
commit 1c402b7c97
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
2 changed files with 29 additions and 4 deletions

View file

@ -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();

View file

@ -17,7 +17,7 @@ test('errors when not run on linux platform', async () => {
expect(coreSpy).toHaveBeenCalledWith('Only supported on linux platform');
});
test('errors without password', async () => {
test('errors without username', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');
@ -25,10 +25,24 @@ test('errors without password', async () => {
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');
@ -37,6 +51,9 @@ 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;
@ -44,7 +61,7 @@ test('successful with only password', async () => {
expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith('');
expect(dockerSpy).toHaveBeenCalledWith('', '', password);
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
});
test('calls docker login', async () => {