Merge pull request #7645 from backstage/rugvip/scaffoodlin
scaffolder-backend: use mock-fs in workflow runner tests
This commit is contained in:
@@ -13,7 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import os from 'os';
|
||||
|
||||
import mockFs from 'mock-fs';
|
||||
import * as winston from 'winston';
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { DefaultWorkflowRunner } from './DefaultWorkflowRunner';
|
||||
import { TemplateActionRegistry } from '../actions';
|
||||
@@ -22,7 +25,6 @@ import { ConfigReader } from '@backstage/config';
|
||||
import { Task, TaskSpec } from './types';
|
||||
|
||||
describe('DefaultWorkflowRunner', () => {
|
||||
const workingDirectory = os.tmpdir();
|
||||
const logger = getVoidLogger();
|
||||
let actionRegistry = new TemplateActionRegistry();
|
||||
let runner: DefaultWorkflowRunner;
|
||||
@@ -45,6 +47,11 @@ describe('DefaultWorkflowRunner', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
winston.format.simple(); // put logform the require cache before mocking fs
|
||||
mockFs({
|
||||
'/tmp': mockFs.directory(),
|
||||
});
|
||||
|
||||
jest.resetAllMocks();
|
||||
actionRegistry = new TemplateActionRegistry();
|
||||
fakeActionHandler = jest.fn();
|
||||
@@ -84,11 +91,15 @@ describe('DefaultWorkflowRunner', () => {
|
||||
runner = new DefaultWorkflowRunner({
|
||||
actionRegistry,
|
||||
integrations,
|
||||
workingDirectory,
|
||||
workingDirectory: '/tmp',
|
||||
logger,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it('should throw an error if the action does not exist', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'scaffolder.backstage.io/v1beta3',
|
||||
|
||||
@@ -13,18 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import mockFs from 'mock-fs';
|
||||
import * as winston from 'winston';
|
||||
import { createTemplateAction, TemplateActionRegistry } from '../actions';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { LegacyWorkflowRunner } from './LegacyWorkflowRunner';
|
||||
import os from 'os';
|
||||
import { Task, TaskSpec } from './types';
|
||||
import { RepoSpec } from '../actions/builtin/publish/util';
|
||||
|
||||
describe('LegacyWorkflowRunner', () => {
|
||||
let runner: LegacyWorkflowRunner;
|
||||
const workingDirectory = os.tmpdir();
|
||||
const logger = getVoidLogger();
|
||||
let actionRegistry = new TemplateActionRegistry();
|
||||
|
||||
@@ -45,6 +46,11 @@ describe('LegacyWorkflowRunner', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
winston.format.simple(); // put logform the require cache before mocking fs
|
||||
mockFs({
|
||||
'/tmp': mockFs.directory(),
|
||||
});
|
||||
|
||||
actionRegistry = new TemplateActionRegistry();
|
||||
actionRegistry.register({
|
||||
id: 'test-action',
|
||||
@@ -57,11 +63,15 @@ describe('LegacyWorkflowRunner', () => {
|
||||
runner = new LegacyWorkflowRunner({
|
||||
actionRegistry,
|
||||
integrations,
|
||||
workingDirectory,
|
||||
workingDirectory: '/tmp',
|
||||
logger,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it('should fail when the action does not exist', async () => {
|
||||
const task = createMockTaskWithSpec({
|
||||
apiVersion: 'backstage.io/v1beta2',
|
||||
|
||||
Reference in New Issue
Block a user