mirror of
https://gitee.com/actions-mirror/docker-login-action
synced 2024-11-23 12:20:43 +08:00
668190adc5
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
65 lines
1.8 KiB
TypeScript
65 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
|
|
});
|
|
});
|