Merge pull request #404 from crazy-max/buildx-localstate-test

buildx: extra test to ensure legit path is not trimmed for localstate
This commit is contained in:
CrazyMax
2024-07-05 16:25:41 +02:00
committed by GitHub
3 changed files with 14 additions and 6 deletions

View File

@@ -288,6 +288,13 @@ describe('localState', () => {
DockerfilePath: '' DockerfilePath: ''
} as LocalState, } as LocalState,
], ],
[
'default/default/dfsz8r57a98zf789pmlyzqp3n',
{
LocalPath: 'https://github.com/docker/actions-toolkit.git#:__tests__/fixtures',
DockerfilePath: 'hello.Dockerfile'
} as LocalState,
],
[ [
'default/default/w38vcd5fo5cfvfyig77qjec0v', 'default/default/w38vcd5fo5cfvfyig77qjec0v',
{ {
@@ -296,7 +303,7 @@ describe('localState', () => {
} as LocalState, } as LocalState,
] ]
])('given %p', async (ref: string, expected: LocalState) => { ])('given %p', async (ref: string, expected: LocalState) => {
const localState = Buildx.localState(path.join(fixturesDir, 'buildx-refs'), ref); const localState = Buildx.localState(ref, path.join(fixturesDir, 'buildx-refs'));
expect(localState).toEqual(expected); expect(localState).toEqual(expected);
}); });
}); });
@@ -306,14 +313,14 @@ describe('refs', () => {
const refs = Buildx.refs({ const refs = Buildx.refs({
dir: path.join(fixturesDir, 'buildx-refs') dir: path.join(fixturesDir, 'buildx-refs')
}); });
expect(Object.keys(refs).length).toEqual(16); expect(Object.keys(refs).length).toEqual(17);
}); });
it('returns default builder refs', async () => { it('returns default builder refs', async () => {
const refs = Buildx.refs({ const refs = Buildx.refs({
dir: path.join(fixturesDir, 'buildx-refs'), dir: path.join(fixturesDir, 'buildx-refs'),
builderName: 'default' builderName: 'default'
}); });
expect(Object.keys(refs).length).toEqual(13); expect(Object.keys(refs).length).toEqual(14);
}); });
it('returns foo builder refs', async () => { it('returns foo builder refs', async () => {
const refs = Buildx.refs({ const refs = Buildx.refs({
@@ -332,6 +339,6 @@ describe('refs', () => {
builderName: 'default', builderName: 'default',
since: new Date('2024-01-10T00:00:00Z') since: new Date('2024-01-10T00:00:00Z')
}); });
expect(Object.keys(refs).length).toEqual(10); expect(Object.keys(refs).length).toEqual(11);
}); });
}); });

View File

@@ -0,0 +1 @@
{"LocalPath":"https://github.com/docker/actions-toolkit.git#:__tests__/fixtures","DockerfilePath":"hello.Dockerfile"}

View File

@@ -177,12 +177,12 @@ export class Buildx {
return driverOpts; return driverOpts;
} }
public static localState(dir: string, ref: string): LocalState { public static localState(ref: string, dir?: string): LocalState {
const [builderName, nodeName, id] = ref.split('/'); const [builderName, nodeName, id] = ref.split('/');
if (!builderName || !nodeName || !id) { if (!builderName || !nodeName || !id) {
throw new Error(`Invalid build reference: ${ref}`); throw new Error(`Invalid build reference: ${ref}`);
} }
const lsPath = path.join(dir, builderName, nodeName, id); const lsPath = path.join(dir || Buildx.refsDir, builderName, nodeName, id);
if (!fs.existsSync(lsPath)) { if (!fs.existsSync(lsPath)) {
throw new Error(`Local state not found in ${lsPath}`); throw new Error(`Local state not found in ${lsPath}`);
} }