2022-03-22 21:09:00 +01:00
|
|
|
import {describe, expect, test} from '@jest/globals';
|
2021-03-29 13:04:53 +02:00
|
|
|
import {Flavor, Transform} from '../src/flavor';
|
|
|
|
|
|
|
|
describe('transform', () => {
|
|
|
|
// prettier-ignore
|
|
|
|
test.each([
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`randomstr`,
|
|
|
|
`latest=auto`
|
|
|
|
],
|
|
|
|
{} as Flavor,
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`unknwown=foo`
|
|
|
|
],
|
|
|
|
{} as Flavor,
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest`,
|
|
|
|
],
|
|
|
|
{} as Flavor,
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest=true`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "true",
|
|
|
|
prefix: "",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest=false`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "false",
|
|
|
|
prefix: "",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest=auto`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest=foo`
|
|
|
|
],
|
|
|
|
{} as Flavor,
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`prefix=sha-`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "sha-",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`suffix=-alpine`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "-alpine",
|
|
|
|
suffixLatest: false,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`latest=false`,
|
|
|
|
`prefix=dev-`,
|
|
|
|
`suffix=-alpine`
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "false",
|
|
|
|
prefix: "dev-",
|
2021-07-05 20:37:02 +02:00
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "-alpine",
|
|
|
|
suffixLatest: false,
|
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`prefix=dev-,onlatest=true`,
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "dev-",
|
|
|
|
prefixLatest: true,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`suffix=-alpine,onlatest=true`,
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "",
|
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "-alpine",
|
|
|
|
suffixLatest: true,
|
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`prefix=dev-,onlatest=true`,
|
|
|
|
`suffix=-alpine,onlatest=true`,
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "dev-",
|
|
|
|
prefixLatest: true,
|
|
|
|
suffix: "-alpine",
|
|
|
|
suffixLatest: true,
|
2021-03-29 13:04:53 +02:00
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
],
|
2021-10-22 13:50:28 +02:00
|
|
|
[
|
|
|
|
[
|
|
|
|
`prefix= `,
|
|
|
|
],
|
|
|
|
{
|
|
|
|
latest: "auto",
|
|
|
|
prefix: "",
|
|
|
|
prefixLatest: false,
|
|
|
|
suffix: "",
|
|
|
|
suffixLatest: false,
|
|
|
|
} as Flavor,
|
|
|
|
false
|
|
|
|
]
|
2022-03-22 21:09:00 +01:00
|
|
|
])('given %p attributes', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
2021-03-29 13:04:53 +02:00
|
|
|
try {
|
|
|
|
const flavor = Transform(inputs);
|
|
|
|
expect(flavor).toEqual(expected);
|
|
|
|
} catch (err) {
|
|
|
|
if (!invalid) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
2022-03-22 21:09:00 +01:00
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2021-03-29 13:04:53 +02:00
|
|
|
expect(true).toBe(invalid);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|