From fe75972f55a4686e9e75c908a345a584cc303064 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 24 Jan 2023 00:13:52 +0100 Subject: [PATCH] buildx: printVersion Signed-off-by: CrazyMax --- __tests__/buildx.test.ts | 23 +++++++++++++++++++++++ __tests__/docker.test.ts | 4 ++-- src/buildx.ts | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index eca89ae..ba49d48 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -135,6 +135,29 @@ describe('isAvailable', () => { }); }); +describe('printVersion', () => { + it('docker cli', () => { + const execSpy = jest.spyOn(exec, 'exec'); + const buildx = new Buildx({ + standalone: false + }); + buildx.printVersion(); + expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx', 'version'], { + failOnStdErr: false + }); + }); + it('standalone', () => { + const execSpy = jest.spyOn(exec, 'exec'); + const buildx = new Buildx({ + standalone: true + }); + buildx.printVersion(); + expect(execSpy).toHaveBeenCalledWith(`buildx`, ['version'], { + failOnStdErr: false + }); + }); +}); + describe('getVersion', () => { it('valid', async () => { const buildx = new Buildx(); diff --git a/__tests__/docker.test.ts b/__tests__/docker.test.ts index 8933fd2..d3ef6e3 100644 --- a/__tests__/docker.test.ts +++ b/__tests__/docker.test.ts @@ -17,7 +17,7 @@ describe('isAvailable', () => { }); describe('printVersion', () => { - it('standard', () => { + it('docker cli', () => { const execSpy = jest.spyOn(exec, 'exec'); Docker.printVersion(false); expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], { @@ -34,7 +34,7 @@ describe('printVersion', () => { }); describe('printInfo', () => { - it('standard', () => { + it('docker cli', () => { const execSpy = jest.spyOn(exec, 'exec'); Docker.printInfo(false); expect(execSpy).toHaveBeenCalledWith(`docker`, ['info'], { diff --git a/src/buildx.ts b/src/buildx.ts index f64da21..08f6d38 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -71,6 +71,13 @@ export class Buildx { }); } + public async printVersion() { + const cmd = this.getCommand(['version']); + await exec.exec(cmd.command, cmd.args, { + failOnStdErr: false + }); + } + public static parseVersion(stdout: string): string { const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/.exec(stdout); if (!matches) {