2022-02-28 02:28:55 -05:00
|
|
|
import {expect, jest, test} from '@jest/globals';
|
2020-10-09 06:30:45 -04:00
|
|
|
import osm = require('os');
|
|
|
|
|
2023-02-21 04:06:17 -05:00
|
|
|
import {main} from '../src/main';
|
2020-10-09 06:30:45 -04:00
|
|
|
import * as docker from '../src/docker';
|
|
|
|
import * as stateHelper from '../src/state-helper';
|
|
|
|
|
2020-10-20 08:41:56 -04:00
|
|
|
test('errors without username and password', async () => {
|
2022-03-21 05:57:36 -04:00
|
|
|
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
2021-06-22 04:39:55 -04:00
|
|
|
process.env['INPUT_LOGOUT'] = 'true'; // default value
|
2023-04-16 20:31:57 -04:00
|
|
|
await expect(main()).rejects.toThrow(new Error('Username and password required'));
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|
|
|
|
|
2020-10-16 12:34:48 -04:00
|
|
|
test('successful with username and password', async () => {
|
2022-03-21 05:57:36 -04:00
|
|
|
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
2022-02-28 02:28:55 -05:00
|
|
|
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
2023-04-16 20:31:57 -04:00
|
|
|
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve());
|
2020-10-16 12:24:41 -04:00
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const username = 'dbowie';
|
2020-10-16 12:34:48 -04:00
|
|
|
process.env[`INPUT_USERNAME`] = username;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const password = 'groundcontrol';
|
2020-10-16 12:24:41 -04:00
|
|
|
process.env[`INPUT_PASSWORD`] = password;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const ecr = 'auto';
|
2021-12-20 04:59:11 -05:00
|
|
|
process.env['INPUT_ECR'] = ecr;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const logout = false;
|
2021-06-22 04:39:55 -04:00
|
|
|
process.env['INPUT_LOGOUT'] = String(logout);
|
|
|
|
|
2023-02-21 04:06:17 -05:00
|
|
|
await main();
|
2020-10-16 12:24:41 -04:00
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
2021-06-22 04:39:55 -04:00
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
2021-12-20 04:59:11 -05:00
|
|
|
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('calls docker login', async () => {
|
2022-03-21 05:57:36 -04:00
|
|
|
jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
2022-02-28 02:28:55 -05:00
|
|
|
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
2023-04-16 20:31:57 -04:00
|
|
|
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(() => Promise.resolve());
|
2020-10-09 06:30:45 -04:00
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const username = 'dbowie';
|
2020-10-09 06:30:45 -04:00
|
|
|
process.env[`INPUT_USERNAME`] = username;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const password = 'groundcontrol';
|
2020-10-09 06:30:45 -04:00
|
|
|
process.env[`INPUT_PASSWORD`] = password;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const registry = 'ghcr.io';
|
2020-10-09 06:30:45 -04:00
|
|
|
process.env[`INPUT_REGISTRY`] = registry;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const ecr = 'auto';
|
2021-12-20 04:59:11 -05:00
|
|
|
process.env['INPUT_ECR'] = ecr;
|
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const logout = true;
|
2021-06-22 04:39:55 -04:00
|
|
|
process.env['INPUT_LOGOUT'] = String(logout);
|
2020-10-09 06:30:45 -04:00
|
|
|
|
2023-02-21 04:06:17 -05:00
|
|
|
await main();
|
2020-10-09 06:30:45 -04:00
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
|
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
2021-12-20 04:59:11 -05:00
|
|
|
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|