Skip to content

Commit 39ef12f

Browse files
authored
Merge pull request #18 from crazy-max/username-required
Username required
2 parents 4b15841 + 1c402b7 commit 39ef12f

File tree

5 files changed

+59
-44
lines changed

5 files changed

+59
-44
lines changed

__tests__/context.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import osm = require('os');
22

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

5+
test('without username getInputs throws errors', async () => {
6+
expect(() => {
7+
getInputs();
8+
}).toThrowError('Input required and not supplied: username');
9+
});
10+
511
test('without password getInputs throws errors', async () => {
12+
process.env['INPUT_USERNAME'] = 'dbowie';
613
expect(() => {
714
getInputs();
815
}).toThrowError('Input required and not supplied: password');
916
});
1017

11-
test('with password getInputs does not error', async () => {
18+
test('with password and username getInputs does not error', async () => {
19+
process.env['INPUT_USERNAME'] = 'dbowie';
1220
process.env['INPUT_PASSWORD'] = 'groundcontrol';
1321
expect(() => {
1422
getInputs();

__tests__/main.test.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,51 @@ test('errors when not run on linux platform', async () => {
1717
expect(coreSpy).toHaveBeenCalledWith('Only supported on linux platform');
1818
});
1919

20+
test('errors without username', async () => {
21+
const platSpy = jest.spyOn(osm, 'platform');
22+
platSpy.mockImplementation(() => 'linux');
23+
24+
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
25+
26+
await run();
27+
28+
expect(coreSpy).toHaveBeenCalledWith('Input required and not supplied: username');
29+
});
30+
2031
test('errors without password', async () => {
2132
const platSpy = jest.spyOn(osm, 'platform');
2233
platSpy.mockImplementation(() => 'linux');
2334

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

37+
const username: string = 'dbowie';
38+
process.env[`INPUT_USERNAME`] = username;
39+
2640
await run();
2741

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

31-
test('successful with only password', async () => {
32-
const platSpy = jest.spyOn(osm, 'platform');
33-
platSpy.mockImplementation(() => 'linux');
34-
35-
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
36-
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
37-
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
38-
dockerSpy.mockImplementation(() => {});
39-
40-
const password: string = 'groundcontrol';
41-
process.env[`INPUT_PASSWORD`] = password;
42-
43-
await run();
44-
45-
expect(setRegistrySpy).toHaveBeenCalledWith('');
46-
expect(setLogoutSpy).toHaveBeenCalledWith('');
47-
expect(dockerSpy).toHaveBeenCalledWith('', '', password);
45+
test('successful with username and password', async () => {
46+
const platSpy = jest.spyOn(osm, 'platform');
47+
platSpy.mockImplementation(() => 'linux');
48+
49+
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
50+
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
51+
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
52+
dockerSpy.mockImplementation(() => {});
53+
54+
const username: string = 'dbowie';
55+
process.env[`INPUT_USERNAME`] = username;
56+
57+
const password: string = 'groundcontrol';
58+
process.env[`INPUT_PASSWORD`] = password;
59+
60+
await run();
61+
62+
expect(setRegistrySpy).toHaveBeenCalledWith('');
63+
expect(setLogoutSpy).toHaveBeenCalledWith('');
64+
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
4865
});
4966

5067
test('calls docker login', async () => {
@@ -66,7 +83,7 @@ test('calls docker login', async () => {
6683
process.env[`INPUT_REGISTRY`] = registry;
6784

6885
const logout: string = 'true';
69-
process.env['INPUT_LOGOUT'] = logout
86+
process.env['INPUT_LOGOUT'] = logout;
7087

7188
await run();
7289

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
required: false
1313
username:
1414
description: 'Username used to log against the Docker registry'
15-
required: false
15+
required: true
1616
password:
1717
description: 'Password or personal access token used to log against the Docker registry'
1818
required: true

dist/index.js

Lines changed: 13 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Inputs {
1010
export function getInputs(): Inputs {
1111
return {
1212
registry: core.getInput('registry'),
13-
username: core.getInput('username'),
13+
username: core.getInput('username', {required: true}),
1414
password: core.getInput('password', {required: true}),
1515
logout: core.getInput('logout')
1616
};

0 commit comments

Comments
 (0)