From 595e2417e82728832d53166a5a8fa46916dd47d1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 23 Jan 2023 10:39:14 +0100 Subject: [PATCH] docker: info method Signed-off-by: CrazyMax --- __tests__/docker.test.ts | 17 +++++++++++++++++ src/docker.ts | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/__tests__/docker.test.ts b/__tests__/docker.test.ts index d99c27d..b15cd6e 100644 --- a/__tests__/docker.test.ts +++ b/__tests__/docker.test.ts @@ -15,3 +15,20 @@ describe('isAvailable', () => { }); }); }); + +describe('info', () => { + it('standard', () => { + const execSpy = jest.spyOn(exec, 'exec'); + Docker.info(); + expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], { + failOnStdErr: false + }); + }); + it('standalone', () => { + const execSpy = jest.spyOn(exec, 'exec'); + Docker.info(true); + expect(execSpy).not.toHaveBeenCalledWith(`docker`, ['version'], { + failOnStdErr: false + }); + }); +}); diff --git a/src/docker.ts b/src/docker.ts index 05dcbec..1e887fd 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core'; import * as exec from '@actions/exec'; export class Docker { @@ -18,4 +19,17 @@ export class Docker { return false; }); } + + public static async info(standalone?: boolean) { + if (standalone) { + core.info(`Docker info skipped in standalone mode`); + } else { + await exec.exec('docker', ['version'], { + failOnStdErr: false + }); + await exec.exec('docker', ['info'], { + failOnStdErr: false + }); + } + } }