Extend template entity schema with if in step

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-05-28 12:39:34 +02:00
parent 6770dddb56
commit 052f42400d
3 changed files with 21 additions and 1 deletions
@@ -54,6 +54,7 @@ describe('templateEntityV1beta2Validator', () => {
input: {
url: './template',
},
if: '{{ parameters.owner }}',
},
],
output: {
@@ -122,16 +123,29 @@ describe('templateEntityV1beta2Validator', () => {
delete (entity as any).spec.steps[0].action;
await expect(validator.check(entity)).rejects.toThrow(/action/);
});
it('accepts missing owner', async () => {
delete (entity as any).spec.owner;
await expect(validator.check(entity)).resolves.toBe(true);
});
it('rejects empty owner', async () => {
(entity as any).spec.owner = '';
await expect(validator.check(entity)).rejects.toThrow(/owner/);
});
it('rejects wrong type owner', async () => {
(entity as any).spec.owner = 5;
await expect(validator.check(entity)).rejects.toThrow(/owner/);
});
it('accepts missing if', async () => {
delete (entity as any).spec.if;
await expect(validator.check(entity)).resolves.toBe(true);
});
it('accepts boolean in if', async () => {
(entity as any).spec.if = true;
await expect(validator.check(entity)).resolves.toBe(true);
});
});
@@ -33,6 +33,7 @@ export interface TemplateEntityV1beta2 extends Entity {
name?: string;
action: string;
input?: JsonObject;
if?: string | boolean;
}>;
output?: { [name: string]: string };
owner?: string;
@@ -45,7 +45,8 @@
"action": "publish:github",
"parameters": {
"repoUrl": "{{ parameters.repoUrl }}"
}
},
"if": "{{ parameters.repoUrl }}"
}
],
"output": {
@@ -128,6 +129,10 @@
"input": {
"type": "object",
"description": "A templated object describing the inputs to the action."
},
"if": {
"type": ["string", "boolean"],
"description": "A templated condition that skips the step when evaluated to false. If the condition is true or not defined, the step is executed."
}
}
}