chore(scaffolder): adding some more tests for scaffolder processor
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
import { JobProcessor } from './processor';
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import Docker from 'dockerode';
|
||||
import { CookieCutter } from '../templater/cookiecutter';
|
||||
import { Preparers } from '../';
|
||||
|
||||
describe('JobProcessor', () => {
|
||||
const mockEntity: TemplateEntityV1alpha1 = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
@@ -40,7 +44,22 @@ describe('JobProcessor', () => {
|
||||
};
|
||||
|
||||
describe('create', () => {
|
||||
it.todo('creates a new job');
|
||||
const templater = new CookieCutter();
|
||||
const preparers = new Preparers();
|
||||
const mockDocker = {} as jest.Mocked<Docker>;
|
||||
it('creates a new job', async () => {
|
||||
const processor = new JobProcessor({
|
||||
dockerClient: mockDocker,
|
||||
preparers,
|
||||
templater,
|
||||
});
|
||||
|
||||
const job = processor.create(mockEntity, { component_id: 'bob' });
|
||||
|
||||
expect(job.id).toMatch(
|
||||
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('process', () => {
|
||||
|
||||
@@ -17,7 +17,7 @@ import { Processor, Job } from './types';
|
||||
import { JsonValue } from '@backstage/config';
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import { PassThrough } from 'stream';
|
||||
import uuid from 'uuid';
|
||||
import * as uuid from 'uuid';
|
||||
import Docker from 'dockerode';
|
||||
import winston from 'winston';
|
||||
import { RequiredTemplateValues, TemplaterBase } from '../templater';
|
||||
|
||||
@@ -105,6 +105,7 @@ describe('CookieCutter Templater', () => {
|
||||
dockerClient: mockDocker,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the result path to the end templated folder', async () => {
|
||||
const tempdir = os.tmpdir();
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ export async function createRouter(
|
||||
const jobProcessor = new JobProcessor({
|
||||
preparers,
|
||||
templater,
|
||||
logger,
|
||||
dockerClient,
|
||||
});
|
||||
|
||||
@@ -47,7 +46,8 @@ export async function createRouter(
|
||||
const job = jobProcessor.get(params.jobId);
|
||||
|
||||
if (!job) {
|
||||
return res.status(404).send({ error: 'job not found' });
|
||||
res.status(404).send({ error: 'job not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.send({
|
||||
@@ -89,9 +89,7 @@ export async function createRouter(
|
||||
const job = jobProcessor.create(mockEntity, { component_id: 'test' });
|
||||
res.status(201).json({ jobId: job.id });
|
||||
|
||||
jobProcessor.run(job);
|
||||
|
||||
// console.warn(templatedPath);
|
||||
jobProcessor.process(job);
|
||||
});
|
||||
|
||||
const app = express();
|
||||
|
||||
Reference in New Issue
Block a user