login-action/__tests__/docker.test.ts
CrazyMax 39efbd2c12
Use built-in getExecOutput
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-22 11:09:31 +02:00

49 lines
1.3 KiB
TypeScript

import {loginStandard, logout} from '../src/docker';
import * as path from 'path';
import * as exec from '@actions/exec';
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
test('loginStandard calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
execSpy.mockImplementation(() =>
Promise.resolve({
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
})
);
const username: string = 'dbowie';
const password: string = 'groundcontrol';
const registry: string = 'https://ghcr.io';
await loginStandard(registry, username, password);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['login', '--password-stdin', '--username', username, registry], {
input: Buffer.from(password),
silent: true,
ignoreReturnCode: true
});
});
test('logout calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
execSpy.mockImplementation(() =>
Promise.resolve({
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
})
);
const registry: string = 'https://ghcr.io';
await logout(registry);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['logout', registry], {
ignoreReturnCode: true
});
});