2020-10-09 06:30:45 -04:00
|
|
|
import osm = require('os');
|
|
|
|
|
|
|
|
import {run} from '../src/main';
|
|
|
|
import * as docker from '../src/docker';
|
|
|
|
import * as stateHelper from '../src/state-helper';
|
|
|
|
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
2020-10-20 08:41:56 -04:00
|
|
|
test('errors without username and password', async () => {
|
2020-10-16 12:34:48 -04:00
|
|
|
const platSpy = jest.spyOn(osm, 'platform');
|
|
|
|
platSpy.mockImplementation(() => 'linux');
|
|
|
|
|
|
|
|
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
|
|
|
|
|
|
|
|
await run();
|
|
|
|
|
2020-10-20 08:41:56 -04:00
|
|
|
expect(coreSpy).toHaveBeenCalledWith('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 () => {
|
2020-10-16 12:24:41 -04:00
|
|
|
const platSpy = jest.spyOn(osm, 'platform');
|
|
|
|
platSpy.mockImplementation(() => 'linux');
|
|
|
|
|
|
|
|
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
|
|
|
|
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
|
|
|
|
dockerSpy.mockImplementation(() => {});
|
|
|
|
|
2020-10-16 12:34:48 -04:00
|
|
|
const username: string = 'dbowie';
|
|
|
|
process.env[`INPUT_USERNAME`] = username;
|
|
|
|
|
2020-10-16 12:24:41 -04:00
|
|
|
const password: string = 'groundcontrol';
|
|
|
|
process.env[`INPUT_PASSWORD`] = password;
|
|
|
|
|
|
|
|
await run();
|
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith('');
|
2020-10-16 12:34:48 -04:00
|
|
|
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('calls docker login', async () => {
|
|
|
|
const platSpy = jest.spyOn(osm, 'platform');
|
|
|
|
platSpy.mockImplementation(() => 'linux');
|
|
|
|
|
|
|
|
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
|
|
|
|
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;
|
|
|
|
|
2020-10-20 08:41:56 -04:00
|
|
|
const registry: string = 'ghcr.io';
|
2020-10-09 06:30:45 -04:00
|
|
|
process.env[`INPUT_REGISTRY`] = registry;
|
|
|
|
|
|
|
|
const logout: string = 'true';
|
2020-10-16 12:24:41 -04:00
|
|
|
process.env['INPUT_LOGOUT'] = logout;
|
2020-10-09 06:30:45 -04:00
|
|
|
|
|
|
|
await run();
|
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
|
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
|
|
|
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password);
|
|
|
|
});
|