-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from actions/move-config-file
Move configuration file location
- Loading branch information
Showing
12 changed files
with
242 additions
and
8,439 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,53 @@ | ||
import {expect, test} from '@jest/globals' | ||
import {readConfigFile} from '../src/config' | ||
import {expect, test, beforeEach} from '@jest/globals' | ||
import {readConfig} from '../src/config' | ||
|
||
test('reads the config file', async () => { | ||
let options = readConfigFile('./__tests__/fixtures/config-allow-sample.yml') | ||
expect(options.fail_on_severity).toEqual('critical') | ||
expect(options.allow_licenses).toEqual(['BSD', 'GPL 2']) | ||
}) | ||
// 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) { | ||
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_ALLOW-LICENSES'] | ||
delete process.env['INPUT_DENY-LICENSES'] | ||
} | ||
|
||
test('the default config path handles .yml and .yaml', async () => { | ||
expect(true).toEqual(true) | ||
beforeEach(() => { | ||
clearInputs() | ||
}) | ||
|
||
test('returns a default config when the config file was not found', async () => { | ||
let options = readConfigFile('fixtures/i-dont-exist') | ||
test('it defaults to low severity', async () => { | ||
const options = readConfig() | ||
expect(options.fail_on_severity).toEqual('low') | ||
expect(options.allow_licenses).toEqual(undefined) | ||
}) | ||
|
||
test('it reads config files with empty options', async () => { | ||
let options = readConfigFile('./__tests__/fixtures/no-licenses-config.yml') | ||
test('it reads custom configs', async () => { | ||
setInput('fail-on-severity', 'critical') | ||
setInput('allow-licenses', ' BSD, GPL 2') | ||
|
||
const options = readConfig() | ||
expect(options.fail_on_severity).toEqual('critical') | ||
expect(options.allow_licenses).toEqual(['BSD', 'GPL 2']) | ||
}) | ||
|
||
test('it defaults to empty allow/deny lists ', async () => { | ||
const options = readConfig() | ||
|
||
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 () => { | ||
expect(() => | ||
readConfigFile('./__tests__/fixtures/conflictive-config.yml') | ||
).toThrow() | ||
setInput('allow-licenses', 'MIT') | ||
setInput('deny-licenses', 'BSD') | ||
|
||
expect(() => readConfig()).toThrow() | ||
}) | ||
|
||
test('it raises an error when given an unknown severity', async () => { | ||
setInput('fail-on-severity', 'zombies') | ||
expect(() => readConfig()).toThrow() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.