Document how we test inputs
This commit is contained in:
+20
-10
@@ -1,13 +1,22 @@
|
|||||||
import * as core from '@actions/core'
|
import {expect, test, beforeEach} from '@jest/globals'
|
||||||
import {expect, test, jest, beforeEach} from '@jest/globals'
|
|
||||||
import {readConfig} from '../src/config'
|
import {readConfig} from '../src/config'
|
||||||
|
|
||||||
beforeEach(() => {
|
// GitHub Action inputs come in the form of environment variables
|
||||||
// reset to our defaults after every test run
|
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
||||||
// TODO find out what the proper way of passing action inputs in tests is
|
function setInput(input: string, value: string) {
|
||||||
|
process.env[`INPUT_${input.toUpperCase()}`] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want a clean ENV before each test. We use `delete`
|
||||||
|
// since we want `undefined` values and not empty strings.
|
||||||
|
function clearInputs() {
|
||||||
delete process.env['INPUT_FAIL-ON-SEVERITY']
|
delete process.env['INPUT_FAIL-ON-SEVERITY']
|
||||||
delete process.env['INPUT_ALLOW-LICENSES']
|
delete process.env['INPUT_ALLOW-LICENSES']
|
||||||
delete process.env['INPUT_DENY-LICENSES']
|
delete process.env['INPUT_DENY-LICENSES']
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
clearInputs()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it defaults to low severity', async () => {
|
test('it defaults to low severity', async () => {
|
||||||
@@ -16,8 +25,8 @@ test('it defaults to low severity', async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('it reads custom configs', async () => {
|
test('it reads custom configs', async () => {
|
||||||
process.env['INPUT_FAIL-ON-SEVERITY'] = 'critical'
|
setInput('fail-on-severity', 'critical')
|
||||||
process.env['INPUT_ALLOW-LICENSES'] = ' BSD, GPL 2 '
|
setInput('allow-licenses', ' BSD, GPL 2')
|
||||||
|
|
||||||
const options = readConfig()
|
const options = readConfig()
|
||||||
expect(options.fail_on_severity).toEqual('critical')
|
expect(options.fail_on_severity).toEqual('critical')
|
||||||
@@ -32,12 +41,13 @@ test('it defaults to empty allow/deny lists ', async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('it raises an error if both an allow and denylist are specified', async () => {
|
test('it raises an error if both an allow and denylist are specified', async () => {
|
||||||
process.env['INPUT_ALLOW-LICENSES'] = 'MIT'
|
setInput('allow-licenses', 'MIT')
|
||||||
process.env['INPUT_DENY-LICENSES'] = 'BSD'
|
setInput('deny-licenses', 'BSD')
|
||||||
|
|
||||||
expect(() => readConfig()).toThrow()
|
expect(() => readConfig()).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it raises an error when given an unknown severity', async () => {
|
test('it raises an error when given an unknown severity', async () => {
|
||||||
process.env['INPUT_FAIL-ON-SEVERITY'] = 'zombies!'
|
setInput('fail-on-severity', 'zombies')
|
||||||
expect(() => readConfig()).toThrow()
|
expect(() => readConfig()).toThrow()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user