mirror of
https://github.com/docker/login-action.git
synced 2024-11-09 15:23:25 +01:00
668190adc5
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import {expect, jest, test} from '@jest/globals';
|
|
import * as path from 'path';
|
|
|
|
import {loginStandard, logout} from '../src/docker';
|
|
|
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
|
|
|
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
|
|
|
|
test('loginStandard calls exec', async () => {
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore
|
|
const execSpy = jest.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
|
return {
|
|
exitCode: expect.any(Number),
|
|
stdout: expect.any(Function),
|
|
stderr: expect.any(Function)
|
|
};
|
|
});
|
|
|
|
const username = 'dbowie';
|
|
const password = 'groundcontrol';
|
|
const registry = 'https://ghcr.io';
|
|
|
|
await loginStandard(registry, username, password);
|
|
|
|
expect(execSpy).toHaveBeenCalledTimes(1);
|
|
const callfunc = execSpy.mock.calls[0];
|
|
if (callfunc && callfunc[1]) {
|
|
// we don't want to check env opt
|
|
callfunc[1].env = undefined;
|
|
}
|
|
expect(execSpy).toHaveBeenCalledWith(['login', '--password-stdin', '--username', username, registry], {
|
|
input: Buffer.from(password),
|
|
silent: true,
|
|
ignoreReturnCode: true
|
|
});
|
|
});
|
|
|
|
test('logout calls exec', async () => {
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore
|
|
const execSpy = jest.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
|
return {
|
|
exitCode: expect.any(Number),
|
|
stdout: expect.any(Function),
|
|
stderr: expect.any(Function)
|
|
};
|
|
});
|
|
|
|
const registry = 'https://ghcr.io';
|
|
|
|
await logout(registry);
|
|
|
|
expect(execSpy).toHaveBeenCalledTimes(1);
|
|
const callfunc = execSpy.mock.calls[0];
|
|
if (callfunc && callfunc[1]) {
|
|
// we don't want to check env opt
|
|
callfunc[1].env = undefined;
|
|
}
|
|
expect(execSpy).toHaveBeenCalledWith(['logout', registry], {
|
|
ignoreReturnCode: true
|
|
});
|
|
});
|