mirror of https://github.com/actions/toolkit
Add tests, getInput should be case-insensitive and trim output
parent
7c079ef90d
commit
5f31b6acfc
|
@ -20,7 +20,7 @@ describe('@actions/core', () => {
|
|||
});
|
||||
|
||||
it('getInput throws on missing required input', () => {
|
||||
expect(() => core.getInput('missing', {required: true})).toThrow('Failed to find input missing');
|
||||
expect(() => core.getInput('missing', {required: true})).toThrow('Input required and not supplied: missing');
|
||||
});
|
||||
|
||||
it('getInput doesnt throw on missing non-required input', () => {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"author": "Bryan MacFarlane <bryanmac@microsoft.com>",
|
||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
||||
"license": "MIT",
|
||||
"main": "lib/lib.js",
|
||||
"main": "lib/core.js",
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "__tests__"
|
||||
|
|
|
@ -34,12 +34,12 @@ export function setSecret(name: string, val: string) {
|
|||
* @returns string
|
||||
*/
|
||||
export function getInput(name: string, options?: im.InputOptions): string {
|
||||
let val:string = process.env['INPUT_' + name];
|
||||
let val: string = process.env['INPUT_' + name.replace(' ', '_').toUpperCase()] || '';
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
|
||||
return val;
|
||||
return val.trim();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue