mirror of
https://github.com/docker/metadata-action.git
synced 2026-01-22 06:28:56 +08:00
feat: enable customization of annotations+labels
Signed-off-by: Brendon Smith <bws@bws.bio>
This commit is contained in:
parent
ed95091677
commit
b0b9842728
4 changed files with 320 additions and 100 deletions
83
__tests__/annotation.test.ts
Normal file
83
__tests__/annotation.test.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import {describe, expect, test} from '@jest/globals';
|
||||
|
||||
import {Transform, Annotation} from '../src/annotation';
|
||||
|
||||
describe('annotation transform', () => {
|
||||
test.each([
|
||||
[
|
||||
[`org.opencontainers.image.version=1.1.1`],
|
||||
[
|
||||
{
|
||||
name: `org.opencontainers.image.version`,
|
||||
value: `1.1.1`,
|
||||
enable: true
|
||||
}
|
||||
] as Annotation[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[`name=my.annotation,value="my value",enable=true`],
|
||||
[
|
||||
{
|
||||
name: `my.annotation`,
|
||||
value: `"my value"`,
|
||||
enable: true
|
||||
}
|
||||
] as Annotation[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[`name=my.annotation,value=myvalue,enable=false`],
|
||||
[
|
||||
{
|
||||
name: `my.annotation`,
|
||||
value: `myvalue`,
|
||||
enable: false
|
||||
}
|
||||
] as Annotation[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[`my.annotation=my value`],
|
||||
[
|
||||
{
|
||||
name: `my.annotation`,
|
||||
value: `my value`,
|
||||
enable: true
|
||||
}
|
||||
] as Annotation[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[`name=,value=val`], // empty name
|
||||
undefined,
|
||||
true
|
||||
],
|
||||
[
|
||||
[`name=org.opencontainers.image.url,enable=false`], // empty value
|
||||
[
|
||||
{
|
||||
name: `org.opencontainers.image.url`,
|
||||
value: null,
|
||||
enable: false
|
||||
}
|
||||
] as Annotation[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[`name=my.annotation,value=myvalue,enable=bar`], // invalid enable
|
||||
undefined,
|
||||
true
|
||||
]
|
||||
])('given %p', async (l: string[], expected: Annotation[] | undefined, invalid: boolean) => {
|
||||
try {
|
||||
const annotations = Transform(l);
|
||||
expect(annotations).toEqual(expected);
|
||||
} catch (err) {
|
||||
if (!invalid) {
|
||||
console.error(err);
|
||||
}
|
||||
expect(invalid).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue