feat: removing the older stuff and updating to work with the new common packages
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
TemplateEntityV1beta3,
|
||||
templateEntityV1beta3Validator as validator,
|
||||
} from './TemplateEntityV1beta3';
|
||||
|
||||
describe('templateEntityV1beta3Validator', () => {
|
||||
let entity: TemplateEntityV1beta3;
|
||||
|
||||
beforeEach(() => {
|
||||
entity = {
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
kind: 'Template',
|
||||
metadata: {
|
||||
name: 'test',
|
||||
},
|
||||
spec: {
|
||||
type: 'website',
|
||||
parameters: {
|
||||
required: ['storePath', 'owner'],
|
||||
properties: {
|
||||
owner: {
|
||||
type: 'string',
|
||||
title: 'Owner',
|
||||
description: 'Who is going to own this component',
|
||||
},
|
||||
},
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
id: 'fetch',
|
||||
name: 'Fetch',
|
||||
action: 'fetch:plan',
|
||||
input: {
|
||||
url: './template',
|
||||
},
|
||||
if: '${{ parameters.owner }}',
|
||||
},
|
||||
],
|
||||
output: {
|
||||
fetchUrl: '${{ steps.fetch.output.targetUrl }}',
|
||||
},
|
||||
owner: 'team-b@example.com',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('happy path: accepts valid data', async () => {
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('ignores unknown apiVersion', async () => {
|
||||
(entity as any).apiVersion = 'backstage.io/v1beta0';
|
||||
await expect(validator.check(entity)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('ignores unknown kind', async () => {
|
||||
(entity as any).kind = 'Wizard';
|
||||
await expect(validator.check(entity)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('rejects missing type', async () => {
|
||||
delete (entity as any).spec.type;
|
||||
await expect(validator.check(entity)).rejects.toThrow(/type/);
|
||||
});
|
||||
|
||||
it('accepts any other type', async () => {
|
||||
(entity as any).spec.type = 'hallo';
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('accepts missing parameters', async () => {
|
||||
delete (entity as any).spec.parameters;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('accepts missing outputs', async () => {
|
||||
delete (entity as any).spec.outputs;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('rejects empty type', async () => {
|
||||
(entity as any).spec.type = '';
|
||||
await expect(validator.check(entity)).rejects.toThrow(/type/);
|
||||
});
|
||||
|
||||
it('rejects missing steps', async () => {
|
||||
delete (entity as any).spec.steps;
|
||||
await expect(validator.check(entity)).rejects.toThrow(/steps/);
|
||||
});
|
||||
|
||||
it('accepts step with missing id', async () => {
|
||||
delete (entity as any).spec.steps[0].id;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('accepts step with missing name', async () => {
|
||||
delete (entity as any).spec.steps[0].name;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('rejects step with missing action', async () => {
|
||||
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.steps[0].if;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('accepts boolean in if', async () => {
|
||||
(entity as any).spec.steps[0].if = true;
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('accepts empty if', async () => {
|
||||
(entity as any).spec.steps[0].if = '';
|
||||
await expect(validator.check(entity)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('rejects wrong type if', async () => {
|
||||
(entity as any).spec.steps[0].if = 5;
|
||||
await expect(validator.check(entity)).rejects.toThrow(/if/);
|
||||
});
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { JsonObject } from '@backstage/config';
|
||||
import type { Entity } from '../entity/Entity';
|
||||
import schema from '../schema/kinds/Template.v1beta3.schema.json';
|
||||
import { ajvCompiledJsonSchemaValidator } from './util';
|
||||
|
||||
/** @public */
|
||||
export interface TemplateEntityV1beta3 extends Entity {
|
||||
apiVersion: 'backstage.io/v1beta3';
|
||||
kind: 'Template';
|
||||
spec: {
|
||||
type: string;
|
||||
parameters?: JsonObject | JsonObject[];
|
||||
steps: Array<{
|
||||
id?: string;
|
||||
name?: string;
|
||||
action: string;
|
||||
input?: JsonObject;
|
||||
if?: string | boolean;
|
||||
}>;
|
||||
output?: { [name: string]: string };
|
||||
owner?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const templateEntityV1beta3Validator =
|
||||
ajvCompiledJsonSchemaValidator(schema);
|
||||
@@ -91,7 +91,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should throw an error if the action does not exist', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
parameters: {},
|
||||
output: {},
|
||||
steps: [{ id: 'test', name: 'name', action: 'does-not-exist' }],
|
||||
@@ -105,7 +105,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
describe('validation', () => {
|
||||
it('should throw an error if the action has a schema and the input does not match', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
parameters: {},
|
||||
output: {},
|
||||
steps: [{ id: 'test', name: 'name', action: 'jest-validated-action' }],
|
||||
@@ -118,7 +118,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should run the action when the validation passes', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
parameters: {},
|
||||
output: {},
|
||||
steps: [
|
||||
@@ -140,7 +140,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
describe('conditionals', () => {
|
||||
it('should execute steps conditionally', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{ id: 'test', name: 'test', action: 'output-action' },
|
||||
{
|
||||
@@ -163,7 +163,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should skips steps conditionally', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{ id: 'test', name: 'test', action: 'output-action' },
|
||||
{
|
||||
@@ -186,7 +186,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should skips steps using the negating equals operator', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{ id: 'test', name: 'test', action: 'output-action' },
|
||||
{
|
||||
@@ -211,7 +211,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
describe('templating', () => {
|
||||
it('should template the input to an action', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -237,7 +237,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should keep the original types for the input and not parse things that arent meant to be parsed', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -265,7 +265,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should template complex values into the action', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -291,7 +291,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('supports really complex structures', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -320,7 +320,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('supports numbers as first class too', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -349,7 +349,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
|
||||
it('should template the output from simple actions', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
@@ -373,7 +373,7 @@ describe('DefaultWorkflowRunner', () => {
|
||||
describe('filters', () => {
|
||||
it('provides the parseRepoUrl filter', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [
|
||||
{
|
||||
id: 'test',
|
||||
|
||||
@@ -49,7 +49,7 @@ type TemplateContext = {
|
||||
};
|
||||
|
||||
const isValidTaskSpec = (taskSpec: TaskSpec): taskSpec is TaskSpecV1beta3 => {
|
||||
return taskSpec.apiVersion === 'backstage.io/v1beta3';
|
||||
return taskSpec.apiVersion === 'scaffolder.backstage.io/v1beta3';
|
||||
};
|
||||
|
||||
const createStepLogger = ({ task, step }: { task: Task; step: TaskStep }) => {
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('TaskWorker', () => {
|
||||
});
|
||||
|
||||
await broker.dispatch({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [{ id: 'test', name: 'test', action: 'not-found-action' }],
|
||||
output: {
|
||||
result: '{{ steps.test.output.testOutput }}',
|
||||
@@ -121,7 +121,7 @@ describe('TaskWorker', () => {
|
||||
});
|
||||
|
||||
const { taskId } = await broker.dispatch({
|
||||
apiVersion: 'backstage.io/v1beta3',
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
steps: [{ id: 'test', name: 'test', action: 'not-found-action' }],
|
||||
output: {
|
||||
result: '{{ steps.test.output.testOutput }}',
|
||||
|
||||
@@ -38,7 +38,7 @@ export class TaskWorker {
|
||||
async runOneTask(task: Task) {
|
||||
try {
|
||||
const { output } =
|
||||
task.spec.apiVersion === 'backstage.io/v1beta3'
|
||||
task.spec.apiVersion === 'scaffolder.backstage.io/v1beta3'
|
||||
? await this.options.runners.workflowRunner.execute(task)
|
||||
: await this.options.runners.legacyWorkflowRunner.execute(task);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user