This repository has been archived on 2025-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
setup-qemu-action/__tests__/context.test.ts
wangdepei c1a3ddefd8
Some checks failed
ci / default (push) Has been cancelled
ci / main (tonistiigi/binfmt:latest, all) (push) Has been cancelled
ci / main (tonistiigi/binfmt:latest, arm64,riscv64,arm) (push) Has been cancelled
ci / main (tonistiigi/binfmt:master, all) (push) Has been cancelled
ci / main (tonistiigi/binfmt:master, arm64,riscv64,arm) (push) Has been cancelled
ci / error (push) Has been cancelled
ci / cache-image (false) (push) Has been cancelled
ci / cache-image (true) (push) Has been cancelled
ci / version (tonistiigi/binfmt:latest) (push) Has been cancelled
ci / version (tonistiigi/binfmt:master) (push) Has been cancelled
ci / version (tonistiigi/binfmt:qemu-v7.0.0) (push) Has been cancelled
init
2025-06-05 13:08:51 +08:00

73 lines
1.8 KiB
TypeScript

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,
new Map<string, string>([
['cache-image', 'true'],
]),
{
image: 'docker.io/tonistiigi/binfmt:latest',
platforms: 'all',
cacheImage: true,
} as context.Inputs
],
[
1,
new Map<string, string>([
['image', 'docker/binfmt:latest'],
['platforms', 'arm64,riscv64,arm'],
['cache-image', 'false'],
]),
{
image: 'docker/binfmt:latest',
platforms: 'arm64,riscv64,arm',
cacheImage: false,
} as context.Inputs
],
[
2,
new Map<string, string>([
['platforms', 'arm64, riscv64, arm '],
['cache-image', 'true'],
]),
{
image: 'docker.io/tonistiigi/binfmt:latest',
platforms: 'arm64,riscv64,arm',
cacheImage: true,
} 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;
}