2022-04-27 16:58:50 +02:00
|
|
|
import {describe, expect, test} from '@jest/globals';
|
2023-02-20 22:32:55 +01:00
|
|
|
|
2022-04-27 16:58:50 +02:00
|
|
|
import {Transform, Image} from '../src/image';
|
|
|
|
|
|
|
|
describe('transform', () => {
|
|
|
|
// prettier-ignore
|
|
|
|
test.each([
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`name/foo`
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: `name/foo`,
|
|
|
|
enable: true,
|
|
|
|
}
|
|
|
|
] as Image[],
|
|
|
|
false
|
|
|
|
],
|
2022-04-28 09:08:21 +02:00
|
|
|
[
|
|
|
|
[
|
|
|
|
`name/foo,name/bar`
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: `name/foo`,
|
|
|
|
enable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: `name/bar`,
|
|
|
|
enable: true,
|
|
|
|
}
|
|
|
|
] as Image[],
|
|
|
|
false
|
|
|
|
],
|
2022-04-27 16:58:50 +02:00
|
|
|
[
|
|
|
|
[
|
|
|
|
`name/foo`,
|
|
|
|
`name/bar`
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: `name/foo`,
|
|
|
|
enable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: `name/bar`,
|
|
|
|
enable: true,
|
|
|
|
}
|
|
|
|
] as Image[],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
`name=name/bar`,
|
|
|
|
`name/foo,enable=false`,
|
2022-05-04 15:02:20 +02:00
|
|
|
`name=ghcr.io/UserName/Foo,enable=true`
|
2022-04-27 16:58:50 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: `name/bar`,
|
|
|
|
enable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: `name/foo`,
|
|
|
|
enable: false,
|
|
|
|
},
|
|
|
|
{
|
2022-05-04 15:02:20 +02:00
|
|
|
name: `ghcr.io/UserName/Foo`,
|
2022-04-27 16:58:50 +02:00
|
|
|
enable: true,
|
|
|
|
},
|
|
|
|
] as Image[],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[`value=name/foo`], undefined, true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[`name/foo,enable=bar`], undefined, true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[`name/foo,bar=baz`], undefined, true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[`name=,enable=true`], undefined, true
|
2022-04-28 09:08:21 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[`name/foo,name=name/bar,enable=true`], undefined, true
|
2022-04-27 16:58:50 +02:00
|
|
|
]
|
2023-04-17 04:42:21 +02:00
|
|
|
])('given %p', async (l: string[], expected: Image[] | undefined, invalid: boolean) => {
|
2022-04-27 16:58:50 +02:00
|
|
|
try {
|
|
|
|
const images = Transform(l);
|
|
|
|
expect(images).toEqual(expected);
|
|
|
|
} catch (err) {
|
|
|
|
if (!invalid) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
|
|
|
expect(true).toBe(invalid);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|