2023-02-19 20:19:05 +00:00
|
|
|
import {beforeEach, describe, expect, test} from '@jest/globals';
|
|
|
|
|
|
|
|
import * as context from '../src/context';
|
|
|
|
|
|
|
|
describe('getInputs', () => {
|
|
|
|
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,
|
2024-07-03 09:42:53 +00:00
|
|
|
new Map<string, string>([
|
|
|
|
['cache-image', 'true'],
|
|
|
|
]),
|
2023-02-19 20:19:05 +00:00
|
|
|
{
|
2024-07-03 09:17:00 +00:00
|
|
|
image: 'docker.io/tonistiigi/binfmt:latest',
|
2023-02-19 20:19:05 +00:00
|
|
|
platforms: 'all',
|
2024-07-03 09:42:53 +00:00
|
|
|
cacheImage: true,
|
2023-02-19 20:19:05 +00:00
|
|
|
} as context.Inputs
|
|
|
|
],
|
|
|
|
[
|
|
|
|
1,
|
|
|
|
new Map<string, string>([
|
|
|
|
['image', 'docker/binfmt:latest'],
|
|
|
|
['platforms', 'arm64,riscv64,arm'],
|
2024-07-03 09:42:53 +00:00
|
|
|
['cache-image', 'false'],
|
2023-02-19 20:19:05 +00:00
|
|
|
]),
|
|
|
|
{
|
|
|
|
image: 'docker/binfmt:latest',
|
|
|
|
platforms: 'arm64,riscv64,arm',
|
2024-07-03 09:42:53 +00:00
|
|
|
cacheImage: false,
|
2023-02-19 20:19:05 +00:00
|
|
|
} as context.Inputs
|
|
|
|
],
|
|
|
|
[
|
|
|
|
2,
|
|
|
|
new Map<string, string>([
|
|
|
|
['platforms', 'arm64, riscv64, arm '],
|
2024-07-03 09:42:53 +00:00
|
|
|
['cache-image', 'true'],
|
2023-02-19 20:19:05 +00:00
|
|
|
]),
|
|
|
|
{
|
2024-07-03 09:17:00 +00:00
|
|
|
image: 'docker.io/tonistiigi/binfmt:latest',
|
2023-02-19 20:19:05 +00:00
|
|
|
platforms: 'arm64,riscv64,arm',
|
2024-07-03 09:42:53 +00:00
|
|
|
cacheImage: true,
|
2023-02-19 20:19:05 +00:00
|
|
|
} 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);
|
|
|
|
});
|
|
|
|
const res = await context.getInputs();
|
|
|
|
expect(res).toEqual(expected);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|