docker: split version and info

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-24 00:06:31 +01:00
parent 3c101c4aee
commit 4f2a155c08
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 37 additions and 15 deletions

View File

@ -16,19 +16,36 @@ describe('isAvailable', () => {
});
});
describe('info', () => {
describe('printVersion', () => {
it('standard', () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.info(false);
Docker.printVersion(false);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], {
failOnStdErr: false
});
});
it('standalone', () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.info(true);
Docker.printVersion(true);
expect(execSpy).not.toHaveBeenCalledWith(`docker`, ['version'], {
failOnStdErr: false
});
});
});
describe('printInfo', () => {
it('standard', () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.printInfo(false);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['info'], {
failOnStdErr: false
});
});
it('standalone', () => {
const execSpy = jest.spyOn(exec, 'exec');
Docker.printInfo(true);
expect(execSpy).not.toHaveBeenCalledWith(`docker`, ['info'], {
failOnStdErr: false
});
});
});

View File

@ -1,4 +1,3 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
export class Docker {
@ -23,17 +22,23 @@ export class Docker {
return dockerAvailable;
}
public static async info(standalone?: boolean) {
const dockerAvailable = standalone ?? !Docker.isAvailable();
if (dockerAvailable) {
core.info(`Docker info skipped in standalone mode`);
} else {
await exec.exec('docker', ['version'], {
failOnStdErr: false
});
await exec.exec('docker', ['info'], {
failOnStdErr: false
});
public static async printVersion(standalone?: boolean) {
const noDocker = standalone ?? !Docker.isAvailable();
if (noDocker) {
return;
}
await exec.exec('docker', ['version'], {
failOnStdErr: false
});
}
public static async printInfo(standalone?: boolean) {
const noDocker = standalone ?? !Docker.isAvailable();
if (noDocker) {
return;
}
await exec.exec('docker', ['info'], {
failOnStdErr: false
});
}
}