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: ',',