Add a test-helpers file.
This commit is contained in:
@@ -2,35 +2,7 @@ import {expect, test, beforeEach} from '@jest/globals'
|
|||||||
import {readConfig} from '../src/config'
|
import {readConfig} from '../src/config'
|
||||||
import {getRefs} from '../src/git-refs'
|
import {getRefs} from '../src/git-refs'
|
||||||
import * as Utils from '../src/utils'
|
import * as Utils from '../src/utils'
|
||||||
|
import {setInput, clearInputs} from './test-helpers'
|
||||||
// GitHub Action inputs come in the form of environment variables
|
|
||||||
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
|
||||||
function setInput(input: string, value: string): void {
|
|
||||||
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(): void {
|
|
||||||
const allowedOptions = [
|
|
||||||
'FAIL-ON-SEVERITY',
|
|
||||||
'FAIL-ON-SCOPES',
|
|
||||||
'ALLOW-LICENSES',
|
|
||||||
'DENY-LICENSES',
|
|
||||||
'ALLOW-GHSAS',
|
|
||||||
'LICENSE-CHECK',
|
|
||||||
'VULNERABILITY-CHECK',
|
|
||||||
'CONFIG-FILE',
|
|
||||||
'BASE-REF',
|
|
||||||
'HEAD-REF',
|
|
||||||
'COMMENT-SUMMARY-IN-PR'
|
|
||||||
]
|
|
||||||
|
|
||||||
// eslint-disable-next-line github/array-foreach
|
|
||||||
allowedOptions.forEach(option => {
|
|
||||||
delete process.env[`INPUT_${option.toUpperCase()}`]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(Utils, 'isSPDXValid').mockReturnValue(true)
|
jest.spyOn(Utils, 'isSPDXValid').mockReturnValue(true)
|
||||||
|
|||||||
@@ -1,35 +1,7 @@
|
|||||||
import {expect, test, beforeEach} from '@jest/globals'
|
import {expect, test, beforeEach} from '@jest/globals'
|
||||||
import {readConfig} from '../src/config'
|
import {readConfig} from '../src/config'
|
||||||
import * as Utils from '../src/utils'
|
import * as Utils from '../src/utils'
|
||||||
|
import {setInput, clearInputs} from './test-helpers'
|
||||||
// GitHub Action inputs come in the form of environment variables
|
|
||||||
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
|
||||||
function setInput(input: string, value: string): void {
|
|
||||||
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(): void {
|
|
||||||
const allowedOptions = [
|
|
||||||
'FAIL-ON-SEVERITY',
|
|
||||||
'FAIL-ON-SCOPES',
|
|
||||||
'ALLOW-LICENSES',
|
|
||||||
'DENY-LICENSES',
|
|
||||||
'ALLOW-GHSAS',
|
|
||||||
'LICENSE-CHECK',
|
|
||||||
'VULNERABILITY-CHECK',
|
|
||||||
'CONFIG-FILE',
|
|
||||||
'BASE-REF',
|
|
||||||
'HEAD-REF',
|
|
||||||
'COMMENT-SUMMARY-IN-PR'
|
|
||||||
]
|
|
||||||
|
|
||||||
// eslint-disable-next-line github/array-foreach
|
|
||||||
allowedOptions.forEach(option => {
|
|
||||||
delete process.env[`INPUT_${option.toUpperCase()}`]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const externalConfig = `fail_on_severity: 'high'
|
const externalConfig = `fail_on_severity: 'high'
|
||||||
allow_licenses: ['GPL-2.0-only']
|
allow_licenses: ['GPL-2.0-only']
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// GitHub Action inputs come in the form of environment variables
|
||||||
|
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
|
||||||
|
export function setInput(input: string, value: string): void {
|
||||||
|
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.
|
||||||
|
export function clearInputs(): void {
|
||||||
|
const allowedOptions = [
|
||||||
|
'FAIL-ON-SEVERITY',
|
||||||
|
'FAIL-ON-SCOPES',
|
||||||
|
'ALLOW-LICENSES',
|
||||||
|
'DENY-LICENSES',
|
||||||
|
'ALLOW-GHSAS',
|
||||||
|
'LICENSE-CHECK',
|
||||||
|
'VULNERABILITY-CHECK',
|
||||||
|
'CONFIG-FILE',
|
||||||
|
'BASE-REF',
|
||||||
|
'HEAD-REF',
|
||||||
|
'COMMENT-SUMMARY-IN-PR'
|
||||||
|
]
|
||||||
|
|
||||||
|
// eslint-disable-next-line github/array-foreach
|
||||||
|
allowedOptions.forEach(option => {
|
||||||
|
delete process.env[`INPUT_${option.toUpperCase()}`]
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user