Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Jan 31, 2024
1 parent 0bffa6d commit f28c812
Showing 1 changed file with 95 additions and 23 deletions.
118 changes: 95 additions & 23 deletions __test__/pi-gen-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,105 @@ describe('PiGenConfig', () => {
})

it.each([
['imgName', ''],
['release', 'foo'],
['deployCompression', 'bzip2'],
['compressionLevel', '15'],
['localeDefault', 'en_DE.UTF-42'],
['targetHostname', undefined],
['keyboardKeymap', ''],
['keyboardLayout', undefined],
['timezoneDefault', 'Europe/Munich'],
['firstUserName', ''],
['wpaEssid', '0'.repeat(33)],
['wpaPassword', '12345'],
['wpaPassword', '0'.repeat(64)],
['setfcap', '0'],
['stageList', []],
['stageList', ['foo']],
['stageList', [tmp.fileSync().name]],
['enableNoobs', 'yes'],
['exportLastStageOnly', 'no']
['imgName', '', 'image-name must not be empty'],
[
'release',
'foo',
'release must be one of ["bookworm", "bullseye", "jessie", "stretch", "buster", "testing"]'
],
[
'deployCompression',
'bzip2',
'compression must be one of ["none", "zip", "gz", "xz"]'
],
[
'compressionLevel',
'15',
'compression-level must be between 0 and 9 (or 9e for xz)'
],
[
'localeDefault',
'en_DE.UTF-42',
'locale is not included in the list of supported locales (retrieved from /usr/share/i18n/SUPPORTED)'
],
['targetHostname', undefined, 'hostname must not be empty'],
['keyboardKeymap', '', 'keyboard-keymap must not be empty'],
['keyboardLayout', undefined, 'keyboard-layout must not be empty'],
[
'timezoneDefault',
'Europe/Munich',
'timezone is not included in output of "timedatectl list-timezones"'
],
['firstUserName', '', 'username must not be empty'],
[
'wpaEssid',
'0'.repeat(33),
'wpa-essid must not be longer than 32 characters'
],
[
'wpaPassword',
'12345',
'wpa-password must be between 8 and 63 characters (or unset)'
],
[
'wpaPassword',
'0'.repeat(64),
'wpa-password must be between 8 and 63 characters (or unset)'
],
['setfcap', '0', 'setfcap should only be set to "1", nothing else'],
['stageList', [], 'stage-list must not be empty'],
[
'stageList',
['foo'],
'stage-list must contain valid pi-gen stage names "stage[0-5]" and/or valid directories'
],
[
'stageList',
[tmp.fileSync().name],
'stage-list must contain valid pi-gen stage names "stage[0-5]" and/or valid directories'
],
[
'enableNoobs',
'yes',
'enable-noobs must be either set to "true" or "false", was: yes'
],
[
'exportLastStageOnly',
'no',
'export-last-stage-only must be either set to "true" or "false", was: no'
]
])(
'rejects %s with invalid value %s',
async (property: string, value: any) => {
const piGenConfig = {...DEFAULT_CONFIG}
async (property: string, value: any, error: string) => {
const piGenConfig = {
...DEFAULT_CONFIG,
stageList: ['stage0', 'stage1', 'stage2']
}
expect(await validateConfig(piGenConfig)).toBeUndefined()

piGenConfig[property as keyof PiGenConfig] = value
expect(async () => await validateConfig(piGenConfig)).rejects.toThrow(
error
)
}
)

it('should work with compressionLevel properly', async () => {
const piGenConfig = {
...DEFAULT_CONFIG,
stageList: ['stage0', 'stage1', 'stage2'],
deployCompression: 'xz',
compressionLevel: '9e'
}

expect(await validateConfig(piGenConfig)).toBeUndefined()
for (const deployCompression of ['none', 'zip', 'gz']) {
piGenConfig.deployCompression = deployCompression
await expect(
async () => await validateConfig(piGenConfig)
).rejects.toThrow()
).rejects.toThrow(
'compression-level must be between 0 and 9 (or 9e for xz)'
)
}
)
})
})

0 comments on commit f28c812

Please sign in to comment.