1
0
Fork 0
mirror of https://github.com/docker/setup-buildx-action.git synced 2025-04-22 16:06:36 +02:00

move args logic to context module and add tests

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-09-19 11:36:58 +02:00
parent 6c48dad5f0
commit 5a9fc40575
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
5 changed files with 145 additions and 41 deletions

View file

@ -1,7 +1,8 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import {beforeEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as uuid from 'uuid';
import * as context from '../src/context';
const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-setup-buildx-')).split(path.sep).join(path.posix.sep);
@ -13,6 +14,95 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return path.join(tmpdir, '.tmpname').split(path.sep).join(path.posix.sep);
});
jest.mock('uuid');
jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d');
describe('getCreateArgs', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
if (!key.startsWith('INPUT_')) {
object[key] = process.env[key];
}
return object;
}, {});
});
// prettier-ignore
test.each([
[
0,
new Map<string, string>([
['install', 'false'],
['use', 'true'],
]),
[
'create',
'--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
'--driver', 'docker-container',
'--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
'--use'
]
],
[
1,
new Map<string, string>([
['driver', 'docker'],
['install', 'false'],
['use', 'true'],
]),
[
'create',
'--name', 'default',
'--driver', 'docker',
'--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
'--use'
]
],
[
2,
new Map<string, string>([
['install', 'false'],
['use', 'false'],
['driver-opts', 'image=moby/buildkit:master\nnetwork=host'],
]),
[
'create',
'--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
'--driver', 'docker-container',
'--driver-opt', 'image=moby/buildkit:master',
'--driver-opt', 'network=host',
'--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host'
]
],
[
3,
new Map<string, string>([
['driver', 'remote'],
['endpoint', 'tls://foo:1234'],
['install', 'false'],
['use', 'true'],
]),
[
'create',
'--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
'--driver', 'remote',
'--use',
'tls://foo:1234'
]
],
])(
'[%d] given %p as inputs, returns %p',
async (num: number, inputs: Map<string, string>, expected: Array<string>) => {
inputs.forEach((value: string, name: string) => {
setInput(name, value);
});
const inp = await context.getInputs();
const res = await context.getCreateArgs(inp, '0.9.0');
expect(res).toEqual(expected);
}
);
});
describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');