buildx: hadDockerExporter

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-23 23:58:13 +01:00
parent 14581244a3
commit 3c101c4aee
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 42 additions and 5 deletions

View File

@ -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<string>, 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<string>, 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<string>, expected: boolean, load: boolean | undefined) => {
expect(Buildx.hasDockerExporter(exporters, load)).toEqual(expected);
});
});

View File

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