bake: additional opts when parsing definition

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-03-26 09:46:22 +01:00
parent 264a0eec2a
commit 341bae465f
3 changed files with 61 additions and 23 deletions

View File

@@ -29,17 +29,20 @@ beforeEach(() => {
jest.clearAllMocks();
});
maybe('parseDefinitions', () => {
maybe('getDefinition', () => {
// prettier-ignore
test.each([
[
['https://github.com/docker/buildx.git#v0.10.4'],
'https://github.com/docker/buildx.git#v0.10.4',
['binaries-cross'],
path.join(fixturesDir, 'bake-buildx-0.10.4-binaries-cross.json')
]
])('given %p', async (sources: string[], targets: string[], out: string) => {
],
])('given %p', async (source: string, targets: string[], out: string) => {
const bake = new Bake();
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
expect(await bake.parseDefinitions(sources, targets)).toEqual(expectedDef);
expect(await bake.getDefinition({
source: source,
targets: targets
})).toEqual(expectedDef);
});
});

View File

@@ -19,6 +19,8 @@ import * as fs from 'fs';
import * as path from 'path';
import {Bake} from '../../src/buildx/bake';
import {ExecOptions} from '@actions/exec';
import {BakeDefinition} from '../../src/types/bake';
const fixturesDir = path.join(__dirname, '..', 'fixtures');
@@ -27,31 +29,38 @@ beforeEach(() => {
jest.clearAllMocks();
});
describe('parseDefinitions', () => {
describe('getDefinition', () => {
// prettier-ignore
test.each([
[
[path.join(fixturesDir, 'bake-01.hcl')],
['validate'],
[],
{silent: true},
path.join(fixturesDir, 'bake-01-validate.json')
],
[
[path.join(fixturesDir, 'bake-02.hcl')],
['build'],
[],
undefined,
path.join(fixturesDir, 'bake-02-build.json')
],
[
[path.join(fixturesDir, 'bake-01.hcl')],
['image'],
['*.output=type=docker', '*.platform=linux/amd64'],
undefined,
path.join(fixturesDir, 'bake-01-overrides.json')
]
])('given %p', async (sources: string[], targets: string[], overrides: string[], out: string) => {
])('given %p', async (files: string[], targets: string[], overrides: string[], execOptions: ExecOptions | undefined, out: string) => {
const bake = new Bake();
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
expect(await bake.parseDefinitions(sources, targets, overrides)).toEqual(expectedDef);
expect(await bake.getDefinition({
files: files,
targets: targets,
overrides: overrides
}, execOptions)).toEqual(expectedDef);
});
});