mirror of
https://github.com/docker/setup-docker-action.git
synced 2025-06-21 10:27:58 +02:00
basic test for context
This commit is contained in:
45
__tests__/context.test.ts
Normal file
45
__tests__/context.test.ts
Normal file
@ -0,0 +1,45 @@
|
||||
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>([
|
||||
['version', '23.0.1'],
|
||||
]),
|
||||
{
|
||||
version: '23.0.1',
|
||||
} 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;
|
||||
}
|
Reference in New Issue
Block a user