2022-02-28 08:28:55 +01:00
|
|
|
import {expect, jest, test} from '@jest/globals';
|
2020-10-09 12:30:45 +02: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 14:41:56 +02:00
|
|
|
test('errors without username and password', async () => {
|
2022-02-28 08:28:55 +01:00
|
|
|
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
2020-10-16 18:34:48 +02:00
|
|
|
|
2021-06-22 10:39:55 +02:00
|
|
|
process.env['INPUT_LOGOUT'] = 'true'; // default value
|
2022-02-28 08:28:55 +01:00
|
|
|
const coreSpy = jest.spyOn(core, 'setFailed');
|
2020-10-16 18:34:48 +02:00
|
|
|
|
|
|
|
await run();
|
2020-10-20 14:41:56 +02:00
|
|
|
expect(coreSpy).toHaveBeenCalledWith('Username and password required');
|
2020-10-09 12:30:45 +02:00
|
|
|
});
|
|
|
|
|
2020-10-16 18:34:48 +02:00
|
|
|
test('successful with username and password', async () => {
|
2022-02-28 08:28:55 +01:00
|
|
|
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
|
|
|
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
|
|
|
const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(jest.fn());
|
2020-10-16 18:24:41 +02:00
|
|
|
|
2020-10-16 18:34:48 +02:00
|
|
|
const username: string = 'dbowie';
|
|
|
|
process.env[`INPUT_USERNAME`] = username;
|
|
|
|
|
2020-10-16 18:24:41 +02:00
|
|
|
const password: string = 'groundcontrol';
|
|
|
|
process.env[`INPUT_PASSWORD`] = password;
|
|
|
|
|
2021-12-20 10:59:11 +01:00
|
|
|
const ecr: string = 'auto';
|
|
|
|
process.env['INPUT_ECR'] = ecr;
|
|
|
|
|
2021-06-22 10:39:55 +02:00
|
|
|
const logout: boolean = false;
|
|
|
|
process.env['INPUT_LOGOUT'] = String(logout);
|
|
|
|
|
2020-10-16 18:24:41 +02:00
|
|
|
await run();
|
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
2021-06-22 10:39:55 +02:00
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
2021-12-20 10:59:11 +01:00
|
|
|
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
|
2020-10-09 12:30:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('calls docker login', async () => {
|
2022-02-28 08:28:55 +01:00
|
|
|
const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
|
|
|
|
const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
|
|
|
|
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
|
|
|
|
const dockerSpy = jest.spyOn(docker, 'login');
|
|
|
|
dockerSpy.mockImplementation(jest.fn());
|
2020-10-09 12:30:45 +02:00
|
|
|
|
|
|
|
const username: string = 'dbowie';
|
|
|
|
process.env[`INPUT_USERNAME`] = username;
|
|
|
|
|
|
|
|
const password: string = 'groundcontrol';
|
|
|
|
process.env[`INPUT_PASSWORD`] = password;
|
|
|
|
|
2020-10-20 14:41:56 +02:00
|
|
|
const registry: string = 'ghcr.io';
|
2020-10-09 12:30:45 +02:00
|
|
|
process.env[`INPUT_REGISTRY`] = registry;
|
|
|
|
|
2021-12-20 10:59:11 +01:00
|
|
|
const ecr: string = 'auto';
|
|
|
|
process.env['INPUT_ECR'] = ecr;
|
|
|
|
|
2021-06-22 10:39:55 +02:00
|
|
|
const logout: boolean = true;
|
|
|
|
process.env['INPUT_LOGOUT'] = String(logout);
|
2020-10-09 12:30:45 +02:00
|
|
|
|
|
|
|
await run();
|
|
|
|
|
|
|
|
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
|
|
|
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
2021-12-20 10:59:11 +01:00
|
|
|
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
|
2020-10-09 12:30:45 +02:00
|
|
|
});
|