From 3c101c4aeead5e28b12c9040bff75409d2fb0e2c Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 23 Jan 2023 23:58:13 +0100 Subject: [PATCH] buildx: hadDockerExporter Signed-off-by: CrazyMax --- __tests__/buildx.test.ts | 43 +++++++++++++++++++++++++++++++++++----- src/buildx.ts | 4 ++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index 24f19f0..eca89ae 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -60,18 +60,51 @@ describe('getDigest', () => { }); }); -describe('hasLocalOrTarExporter', () => { +describe('hasLocalExporter', () => { + // prettier-ignore test.each([ [['type=registry,ref=user/app'], false], [['type=docker'], false], [['type=local,dest=./release-out'], true], - [['type=tar,dest=/tmp/image.tar'], true], - [['type=docker', 'type=tar,dest=/tmp/image.tar'], true], - [['"type=tar","dest=/tmp/image.tar"'], true], + [['type=tar,dest=/tmp/image.tar'], false], + [['type=docker', 'type=tar,dest=/tmp/image.tar'], false], + [['"type=tar","dest=/tmp/image.tar"'], false], [['" type= local" , dest=./release-out'], true], [['.'], true] ])('given %p returns %p', async (exporters: Array, expected: boolean) => { - expect(Buildx.hasLocalExporter(exporters) || Buildx.hasTarExporter(exporters)).toEqual(expected); + expect(Buildx.hasLocalExporter(exporters)).toEqual(expected); + }); +}); + +describe('hasTarExporter', () => { + // prettier-ignore + test.each([ + [['type=registry,ref=user/app'], false], + [['type=docker'], false], + [['type=local,dest=./release-out'], false], + [['type=tar,dest=/tmp/image.tar'], true], + [['type=docker', 'type=tar,dest=/tmp/image.tar'], true], + [['"type=tar","dest=/tmp/image.tar"'], true], + [['" type= local" , dest=./release-out'], false], + [['.'], false] + ])('given %p returns %p', async (exporters: Array, expected: boolean) => { + expect(Buildx.hasTarExporter(exporters)).toEqual(expected); + }); +}); + +describe('hasDockerExporter', () => { + // prettier-ignore + test.each([ + [['type=registry,ref=user/app'], false, undefined], + [['type=docker'], true, undefined], + [['type=local,dest=./release-out'], false, undefined], + [['type=tar,dest=/tmp/image.tar'], false, undefined], + [['type=docker', 'type=tar,dest=/tmp/image.tar'], true, undefined], + [['"type=tar","dest=/tmp/image.tar"'], false, undefined], + [['" type= local" , dest=./release-out'], false, undefined], + [['.'], true, true], + ])('given %p returns %p', async (exporters: Array, expected: boolean, load: boolean | undefined) => { + expect(Buildx.hasDockerExporter(exporters, load)).toEqual(expected); }); }); diff --git a/src/buildx.ts b/src/buildx.ts index 73a8e43..f64da21 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -157,6 +157,10 @@ export class Buildx { return Buildx.hasExporterType('tar', exporters); } + public static hasDockerExporter(exporters: string[], load?: boolean): boolean { + return load ?? Buildx.hasExporterType('docker', exporters); + } + public static hasExporterType(name: string, exporters: string[]): boolean { const records = parse(exporters.join(`\n`), { delimiter: ',',