2022-02-28 02:28:55 -05:00
|
|
|
import {expect, jest, test} from '@jest/globals';
|
2021-12-20 04:43:09 -05:00
|
|
|
import {loginStandard, logout} from '../src/docker';
|
2020-10-09 06:30:45 -04:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as exec from '@actions/exec';
|
|
|
|
|
|
|
|
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
|
|
|
|
|
|
|
|
test('loginStandard calls exec', async () => {
|
2022-03-21 05:57:36 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2022-02-28 02:28:55 -05:00
|
|
|
// @ts-ignore
|
|
|
|
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
|
|
|
return {
|
2021-06-22 05:09:26 -04:00
|
|
|
exitCode: expect.any(Number),
|
|
|
|
stdout: expect.any(Function),
|
|
|
|
stderr: expect.any(Function)
|
2022-02-28 02:28:55 -05:00
|
|
|
};
|
|
|
|
});
|
2020-10-09 06:30:45 -04:00
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const username = 'dbowie';
|
|
|
|
const password = 'groundcontrol';
|
|
|
|
const registry = 'https://ghcr.io';
|
2020-10-09 06:30:45 -04:00
|
|
|
|
|
|
|
await loginStandard(registry, username, password);
|
|
|
|
|
|
|
|
expect(execSpy).toHaveBeenCalledWith(`docker`, ['login', '--password-stdin', '--username', username, registry], {
|
|
|
|
input: Buffer.from(password),
|
|
|
|
silent: true,
|
2021-06-22 05:09:26 -04:00
|
|
|
ignoreReturnCode: true
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('logout calls exec', async () => {
|
2022-03-21 05:57:36 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2022-02-28 02:28:55 -05:00
|
|
|
// @ts-ignore
|
|
|
|
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
|
|
|
return {
|
2021-06-22 05:09:26 -04:00
|
|
|
exitCode: expect.any(Number),
|
|
|
|
stdout: expect.any(Function),
|
|
|
|
stderr: expect.any(Function)
|
2022-02-28 02:28:55 -05:00
|
|
|
};
|
|
|
|
});
|
2020-10-09 06:30:45 -04:00
|
|
|
|
2022-03-21 05:57:36 -04:00
|
|
|
const registry = 'https://ghcr.io';
|
2020-10-09 06:30:45 -04:00
|
|
|
|
|
|
|
await logout(registry);
|
|
|
|
|
|
|
|
expect(execSpy).toHaveBeenCalledWith(`docker`, ['logout', registry], {
|
2021-06-22 05:09:26 -04:00
|
|
|
ignoreReturnCode: true
|
2020-10-09 06:30:45 -04:00
|
|
|
});
|
|
|
|
});
|