docker: fix printVersion and printInfo

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-19 02:47:49 +01:00
parent cd825ae548
commit e9db81b6a1
2 changed files with 10 additions and 46 deletions

View File

@@ -60,43 +60,21 @@ describe('isAvailable', () => {
});
describe('printVersion', () => {
it('docker cli', async () => {
it('call docker version', async () => {
const execSpy = jest.spyOn(exec, 'exec');
await Docker.printVersion(false).catch(() => {
await Docker.printVersion().catch(() => {
// noop
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], {
failOnStdErr: false
});
});
it('standalone', async () => {
const execSpy = jest.spyOn(exec, 'exec');
await Docker.printVersion(true).catch(() => {
// noop
});
expect(execSpy).not.toHaveBeenCalledWith(`docker`, ['version'], {
failOnStdErr: false
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version']);
});
});
describe('printInfo', () => {
it('docker cli', () => {
it('call docker info', async () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.printInfo(false).catch(() => {
await Docker.printInfo().catch(() => {
// noop
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['info'], {
failOnStdErr: false
});
});
it('standalone', () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.printInfo(true).catch(() => {
// noop
});
expect(execSpy).not.toHaveBeenCalledWith(`docker`, ['info'], {
failOnStdErr: false
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['info']);
});
});

View File

@@ -46,25 +46,11 @@ export class Docker {
return ok;
}
public static async printVersion(standalone?: boolean): Promise<void> {
const noDocker = standalone ?? !(await Docker.isAvailable());
if (noDocker) {
core.debug('Docker.printVersion: Docker is not available, skipping.');
return;
}
await exec.exec('docker', ['version'], {
failOnStdErr: false
});
public static async printVersion(): Promise<void> {
await exec.exec('docker', ['version']);
}
public static async printInfo(standalone?: boolean): Promise<void> {
const noDocker = standalone ?? !(await Docker.isAvailable());
if (noDocker) {
core.debug('Docker.printInfo: Docker is not available, skipping.');
return;
}
await exec.exec('docker', ['info'], {
failOnStdErr: false
});
public static async printInfo(): Promise<void> {
await exec.exec('docker', ['info']);
}
}