Don't set the defaults in the test :/

This commit is contained in:
Federico Builes
2022-06-14 07:04:26 +02:00
parent efecf6fd09
commit ef97470a0f
2 changed files with 13 additions and 15 deletions
+1 -2
View File
@@ -4,14 +4,13 @@ import {readConfig} from '../src/config'
beforeEach(() => {
/* reset to our defaults after every test run */
process.env['INPUT_FAIL-ON-SEVERITY'] = 'low'
delete process.env['INPUT_FAIL-ON-SEVERITY']
delete process.env['INPUT_ALLOWED-LICENSES']
delete process.env['INPUT_DENY-LICENSES']
})
test('it defaults to low severity', async () => {
let options = readConfig()
expect(options.fail_on_severity).toEqual('low')
})
+12 -13
View File
@@ -1,22 +1,19 @@
import * as core from '@actions/core'
import {z} from 'zod'
import {ConfigurationOptions, ConfigurationOptionsSchema} from './schemas'
import {Severity} from './schemas'
export const CONFIG_FILEPATH = './.github/dependency-review.yml'
import {
ConfigurationOptions,
ConfigurationOptionsSchema,
Severity
} from './schemas'
export function readConfig(): ConfigurationOptions {
// By default we want to fail on all severities and allow all licenses.
let options: ConfigurationOptions = {}
let severity = core.getInput('fail-on-severity')
let allowedLicenses = core.getInput('allowed-licenses')
let denyLicenses = core.getInput('deny-licenses')
// By default we want to fail on all severities and allow all licenses.
const severity = core.getInput('fail-on-severity') || 'low'
const allowedLicenses = core.getInput('allowed-licenses')
const denyLicenses = core.getInput('deny-licenses')
// TODO test the empty string case
if (severity.length > 0) {
options.fail_on_severity = severity as Severity
}
options.fail_on_severity = severity as Severity
if (allowedLicenses.length > 0) {
options.allow_licenses = allowedLicenses.split(',').map(s => s.trim())
@@ -26,5 +23,7 @@ export function readConfig(): ConfigurationOptions {
options.deny_licenses = denyLicenses.split(',').map(s => s.trim())
}
// we call parse on the ConfigurationOptions object because we want Zod
// to validate part of the input.
return ConfigurationOptionsSchema.parse(options)
}