docker: context method

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-02-25 12:20:06 +01:00
parent 2e59ae7030
commit 97e647fdd0
2 changed files with 25 additions and 0 deletions

View File

@@ -57,6 +57,19 @@ describe('isAvailable', () => {
});
});
describe('context', () => {
it('call docker context show', async () => {
const execSpy = jest.spyOn(Exec, 'getExecOutput');
await Docker.context().catch(() => {
// noop
});
expect(execSpy).toHaveBeenCalledWith(`docker`, ['context', 'show'], {
ignoreReturnCode: true,
silent: true
});
});
});
describe('printVersion', () => {
it('call docker version', async () => {
const execSpy = jest.spyOn(Exec, 'exec');

View File

@@ -38,6 +38,18 @@ export class Docker {
});
}
public static async context(): Promise<string> {
return await Exec.getExecOutput(`docker`, ['context', 'show'], {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
}
public static async printVersion(): Promise<void> {
await Exec.exec('docker', ['version']);
}