2022-06-13 19:55:08 +02:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
|
import {expect, test, jest, beforeEach} from '@jest/globals'
|
|
|
|
|
import {readConfig} from '../src/config'
|
2022-05-26 15:54:59 -07:00
|
|
|
|
2022-06-13 19:55:08 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
|
/* reset to our defaults after every test run */
|
|
|
|
|
process.env['INPUT_FAIL-ON-SEVERITY'] = 'low'
|
|
|
|
|
process.env['INPUT_ALLOWED-LICENSES'] = ''
|
|
|
|
|
process.env['INPUT_DENY-LICENSES'] = ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('it defaults to low severity', async () => {
|
|
|
|
|
let options = readConfig()
|
|
|
|
|
expect(options.fail_on_severity).toEqual('low')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('it reads custom configs', async () => {
|
|
|
|
|
process.env['INPUT_FAIL-ON-SEVERITY'] = 'critical'
|
|
|
|
|
process.env['INPUT_ALLOWED-LICENSES'] = ' BSD, GPL 2 '
|
|
|
|
|
|
|
|
|
|
let options = readConfig()
|
2022-06-01 12:09:11 +02:00
|
|
|
expect(options.fail_on_severity).toEqual('critical')
|
|
|
|
|
expect(options.allow_licenses).toEqual(['BSD', 'GPL 2'])
|
2022-05-26 15:54:59 -07:00
|
|
|
})
|
|
|
|
|
|
2022-06-13 19:55:08 +02:00
|
|
|
test('it defaults to empty allow/deny lists ', async () => {
|
|
|
|
|
let options = readConfig()
|
2022-05-26 15:54:59 -07:00
|
|
|
|
2022-06-06 17:07:26 +02:00
|
|
|
expect(options.allow_licenses).toEqual(undefined)
|
|
|
|
|
expect(options.deny_licenses).toEqual(undefined)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('it raises an error if both an allow and denylist are specified', async () => {
|
2022-06-13 19:55:08 +02:00
|
|
|
process.env['INPUT_ALLOWED-LICENSES'] = 'MIT'
|
|
|
|
|
process.env['INPUT_DENY-LICENSES'] = 'BSD'
|
|
|
|
|
expect(() => readConfig()).toThrow()
|
2022-06-06 17:07:26 +02:00
|
|
|
})
|
2022-06-13 19:55:08 +02:00
|
|
|
|
|
|
|
|
test('it raises an error when given an unknown severity', async () => {})
|