use new MockDirectory symlink helper
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -452,16 +452,13 @@ describe('backend-plugin-manager', () => {
|
||||
findPaths(__dirname).resolveTargetRoot('package.json'),
|
||||
),
|
||||
'dynamic-plugins-root': {},
|
||||
'dynamic-plugins-root/a-dynamic-plugin': ctx =>
|
||||
ctx.symlink(otherMockDir.resolve('a-dynamic-plugin')),
|
||||
});
|
||||
otherMockDir.setContent({
|
||||
'a-dynamic-plugin': {},
|
||||
});
|
||||
|
||||
fs.symlinkSync(
|
||||
otherMockDir.resolve('a-dynamic-plugin'),
|
||||
mockDir.resolve('dynamic-plugins-root/a-dynamic-plugin'),
|
||||
);
|
||||
|
||||
const fromConfigSpier = jest.spyOn(PluginManager, 'fromConfig');
|
||||
const applyConfigSpier = jest
|
||||
.spyOn(PluginScanner.prototype as any, 'applyConfig')
|
||||
|
||||
@@ -19,10 +19,12 @@ import { JsonObject } from '@backstage/types';
|
||||
import { Logs, MockedLogger } from '../__testUtils__/testUtils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import * as url from 'url';
|
||||
import { ScannedPluginPackage } from './types';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
MockDirectoryContent,
|
||||
createMockDirectory,
|
||||
} from '@backstage/backend-test-utils';
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
|
||||
@@ -233,8 +235,7 @@ Please add '${mockDir.resolve(
|
||||
type TestCase = {
|
||||
name: string;
|
||||
preferAlpha?: boolean;
|
||||
fileSystem?: any;
|
||||
symlinks?: { source: string; target: string }[];
|
||||
fileSystem?: MockDirectoryContent;
|
||||
expectedLogs?: Logs;
|
||||
expectedPluginPackages?: ScannedPluginPackage[];
|
||||
expectedError?: string;
|
||||
@@ -286,7 +287,12 @@ Please add '${mockDir.resolve(
|
||||
name: 'backend plugin found in symlink',
|
||||
fileSystem: {
|
||||
backstageRoot: {
|
||||
'dist-dynamic': {},
|
||||
'dist-dynamic': {
|
||||
'test-backend-plugin': ctx =>
|
||||
ctx.symlink(
|
||||
mockDir.resolve('somewhere-else/test-backend-plugin-target'),
|
||||
),
|
||||
},
|
||||
},
|
||||
'somewhere-else': {
|
||||
'test-backend-plugin-target': {
|
||||
@@ -299,16 +305,6 @@ Please add '${mockDir.resolve(
|
||||
},
|
||||
},
|
||||
},
|
||||
symlinks: [
|
||||
{
|
||||
source: mockDir.resolve(
|
||||
'backstageRoot/dist-dynamic/test-backend-plugin',
|
||||
),
|
||||
target: mockDir.resolve(
|
||||
'somewhere-else/test-backend-plugin-target',
|
||||
),
|
||||
},
|
||||
],
|
||||
expectedPluginPackages: [
|
||||
{
|
||||
location: url.pathToFileURL(
|
||||
@@ -347,22 +343,17 @@ Please add '${mockDir.resolve(
|
||||
name: 'ignored folder child symlink: target is not a directory',
|
||||
fileSystem: {
|
||||
backstageRoot: {
|
||||
'dist-dynamic': {},
|
||||
'dist-dynamic': {
|
||||
'test-backend-plugin': ctx =>
|
||||
ctx.symlink(
|
||||
mockDir.resolve('somewhere-else/test-backend-plugin-target'),
|
||||
),
|
||||
},
|
||||
},
|
||||
'somewhere-else': {
|
||||
'test-backend-plugin-target': '',
|
||||
},
|
||||
},
|
||||
symlinks: [
|
||||
{
|
||||
source: mockDir.resolve(
|
||||
'backstageRoot/dist-dynamic/test-backend-plugin',
|
||||
),
|
||||
target: mockDir.resolve(
|
||||
'somewhere-else/test-backend-plugin-target',
|
||||
),
|
||||
},
|
||||
],
|
||||
expectedPluginPackages: [],
|
||||
expectedLogs: {
|
||||
infos: [
|
||||
@@ -637,11 +628,6 @@ Please add '${mockDir.resolve(
|
||||
if (tc.fileSystem) {
|
||||
mockDir.setContent(tc.fileSystem);
|
||||
}
|
||||
if (tc.symlinks) {
|
||||
for (const { source, target } of tc.symlinks) {
|
||||
fs.symlinkSync(target, source);
|
||||
}
|
||||
}
|
||||
if (tc.expectedError) {
|
||||
/* eslint-disable-next-line jest/no-conditional-expect */
|
||||
expect(toTest).toThrow(tc.expectedError);
|
||||
|
||||
@@ -19,7 +19,7 @@ jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
return { ...actual, fetchContents: jest.fn() };
|
||||
});
|
||||
|
||||
import { join as joinPath, resolve as resolvePath, sep as pathSep } from 'path';
|
||||
import { join as joinPath, sep as pathSep } from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {
|
||||
getVoidLogger,
|
||||
@@ -272,27 +272,16 @@ describe('fetch:template', () => {
|
||||
},
|
||||
'.${{ values.name }}': '${{ values.itemList | dump }}',
|
||||
'a-binary-file.png': aBinaryFile,
|
||||
'an-executable.sh': ctx =>
|
||||
fs.writeFileSync(ctx.path, '#!/usr/bin/env bash', {
|
||||
encoding: 'utf-8',
|
||||
mode: parseInt('100755', 8),
|
||||
}),
|
||||
symlink: ctx => ctx.symlink('a-binary-file.png'),
|
||||
brokenSymlink: ctx => ctx.symlink('./not-a-real-file.txt'),
|
||||
},
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
resolvePath(outputPath, 'an-executable.sh'),
|
||||
'#!/usr/bin/env bash',
|
||||
{
|
||||
encoding: 'utf-8',
|
||||
mode: parseInt('100755', 8),
|
||||
},
|
||||
);
|
||||
|
||||
fs.symlinkSync(
|
||||
'a-binary-file.png',
|
||||
resolvePath(outputPath, 'symlink'),
|
||||
);
|
||||
fs.symlinkSync(
|
||||
'./not-a-real-file.txt',
|
||||
resolvePath(outputPath, 'brokenSymlink'),
|
||||
);
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user