1
0
Files
login-action/__tests__/docker.test.ts
T

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-02-28 08:28:55 +01:00
import {expect, jest, test} from '@jest/globals';
import {loginStandard, logout} from '../src/docker';
2020-10-09 03:30:45 -07: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-02-28 08:28:55 +01:00
// @ts-ignore
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return {
2021-06-22 11:09:26 +02:00
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
2022-02-28 08:28:55 +01:00
};
});
2020-10-09 03:30:45 -07:00
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,
2021-06-22 11:09:26 +02:00
ignoreReturnCode: true
2020-10-09 03:30:45 -07:00
});
});
test('logout calls exec', async () => {
2022-02-28 08:28:55 +01:00
// @ts-ignore
const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return {
2021-06-22 11:09:26 +02:00
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
2022-02-28 08:28:55 +01:00
};
});
2020-10-09 03:30:45 -07:00
const registry: string = 'https://ghcr.io';
await logout(registry);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['logout', registry], {
2021-06-22 11:09:26 +02:00
ignoreReturnCode: true
2020-10-09 03:30:45 -07:00
});
});