2023-02-20 22:32:55 +01:00
|
|
|
import {beforeEach, describe, expect, test} from '@jest/globals';
|
2020-12-24 04:13:41 +01:00
|
|
|
|
2020-10-25 02:25:23 +01:00
|
|
|
import * as context from '../src/context';
|
|
|
|
|
2023-02-20 22:32:55 +01:00
|
|
|
describe('getInputs', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
process.env = Object.keys(process.env).reduce((object, key) => {
|
|
|
|
if (!key.startsWith('INPUT_')) {
|
|
|
|
object[key] = process.env[key];
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}, {});
|
2020-12-23 22:09:38 +01:00
|
|
|
});
|
|
|
|
|
2023-02-20 22:32:55 +01:00
|
|
|
// prettier-ignore
|
|
|
|
test.each([
|
|
|
|
[
|
|
|
|
0,
|
|
|
|
new Map<string, string>([
|
|
|
|
['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'],
|
|
|
|
]),
|
|
|
|
{
|
|
|
|
bakeTarget: 'docker-metadata-action',
|
|
|
|
flavor: [],
|
|
|
|
githubToken: '',
|
|
|
|
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
|
|
|
|
labels: [],
|
|
|
|
sepLabels: '\n',
|
|
|
|
sepTags: '\n',
|
|
|
|
tags: [],
|
|
|
|
} as context.Inputs
|
|
|
|
],
|
|
|
|
[
|
|
|
|
1,
|
|
|
|
new Map<string, string>([
|
|
|
|
['bake-target', 'metadata'],
|
|
|
|
['images', 'moby/buildkit'],
|
|
|
|
['sep-labels', ','],
|
|
|
|
['sep-tags', ','],
|
|
|
|
]),
|
|
|
|
{
|
|
|
|
bakeTarget: 'metadata',
|
|
|
|
flavor: [],
|
|
|
|
githubToken: '',
|
|
|
|
images: ['moby/buildkit'],
|
|
|
|
labels: [],
|
|
|
|
sepLabels: ',',
|
|
|
|
sepTags: ',',
|
|
|
|
tags: [],
|
|
|
|
} as context.Inputs
|
|
|
|
]
|
|
|
|
])(
|
|
|
|
'[%d] given %p as inputs, returns %p',
|
|
|
|
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
|
|
|
inputs.forEach((value: string, name: string) => {
|
|
|
|
setInput(name, value);
|
|
|
|
});
|
|
|
|
expect(await context.getInputs()).toEqual(expected);
|
|
|
|
}
|
|
|
|
);
|
2020-10-25 02:25:23 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
|
|
|
function getInputName(name: string): string {
|
|
|
|
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setInput(name: string, value: string): void {
|
|
|
|
process.env[getInputName(name)] = value;
|
|
|
|
}
|