1
0
Files

80 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2026-02-28 01:52:41 +01:00
import {beforeEach, describe, expect, test} from 'vitest';
2023-02-19 21:19:05 +01:00
2026-02-28 02:03:44 +01:00
import * as context from '../src/context.js';
2023-02-19 21:19:05 +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;
}, {});
});
// prettier-ignore
2026-02-28 01:52:41 +01:00
const cases: [number, Map<string, string>, context.Inputs][] = [
2023-02-19 21:19:05 +01:00
[
0,
new Map<string, string>([
2026-05-27 17:01:22 +02:00
['reset', 'false'],
['cache-image', 'true'],
]),
2023-02-19 21:19:05 +01:00
{
image: 'docker.io/tonistiigi/binfmt:latest',
2023-02-19 21:19:05 +01:00
platforms: 'all',
2026-05-27 17:01:22 +02:00
reset: false,
cacheImage: true,
2026-02-28 01:52:41 +01:00
}
2023-02-19 21:19:05 +01:00
],
[
1,
new Map<string, string>([
['image', 'docker/binfmt:latest'],
['platforms', 'arm64,riscv64,arm'],
2026-05-27 17:01:22 +02:00
['reset', 'false'],
['cache-image', 'false'],
2023-02-19 21:19:05 +01:00
]),
{
image: 'docker/binfmt:latest',
platforms: 'arm64,riscv64,arm',
2026-05-27 17:01:22 +02:00
reset: false,
cacheImage: false,
2026-02-28 01:52:41 +01:00
}
2023-02-19 21:19:05 +01:00
],
[
2,
new Map<string, string>([
['platforms', 'arm64, riscv64, arm '],
2026-05-27 17:01:22 +02:00
['reset', 'false'],
['cache-image', 'true'],
2023-02-19 21:19:05 +01:00
]),
{
image: 'docker.io/tonistiigi/binfmt:latest',
2023-02-19 21:19:05 +01:00
platforms: 'arm64,riscv64,arm',
2026-05-27 17:01:22 +02:00
reset: false,
cacheImage: true,
2026-02-28 01:52:41 +01:00
}
2023-02-19 21:19:05 +01:00
]
2026-02-28 01:52:41 +01:00
];
test.each(cases)(
'[%d] given %o as inputs, returns %o',
2023-02-19 21:19:05 +01:00
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;
}