feat: omit default namespace in catalog-import

This commit is contained in:
Andrew Thauer
2021-02-18 22:58:57 -05:00
parent 1b095ec92f
commit a8953a9c92
3 changed files with 51 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-import': patch
---
Omits the entity namespace from a generated entity when it has not be explicitly defined in the analyze-location result.
@@ -21,7 +21,10 @@ import { act, render, RenderResult } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { AnalyzeResult, catalogImportApiRef } from '../../api';
import { StepPrepareCreatePullRequest } from './StepPrepareCreatePullRequest';
import {
generateEntities,
StepPrepareCreatePullRequest,
} from './StepPrepareCreatePullRequest';
describe('<StepPrepareCreatePullRequest />', () => {
const catalogImportApi: jest.Mocked<typeof catalogImportApiRef.T> = {
@@ -60,6 +63,7 @@ describe('<StepPrepareCreatePullRequest />', () => {
kind: 'Component',
metadata: {
name: 'my-component',
namespace: 'default',
},
spec: {
owner: 'my-owner',
@@ -284,4 +288,44 @@ spec:
][0],
).toMatchObject({ groups: ['Group:my-group'], groupsLoading: false });
});
describe('generateEntities', () => {
it.each([[undefined], [null]])(
'should not include blank namespace for %s',
namespace => {
expect(
generateEntities(
[{ metadata: { namespace: namespace as any } }],
'my-component',
'group-1',
),
).toEqual([
expect.objectContaining({
metadata: expect.not.objectContaining({
namespace: 'default',
}),
}),
]);
},
);
it.each([['default'], ['my-namespace']])(
'should include explicit namespace %s',
namespace => {
expect(
generateEntities(
[{ metadata: { namespace } }],
'my-component',
'group-1',
),
).toEqual([
expect.objectContaining({
metadata: expect.objectContaining({
namespace,
}),
}),
]);
},
);
});
});
@@ -66,7 +66,7 @@ type Props = {
) => React.ReactNode;
};
function generateEntities(
export function generateEntities(
entities: PartialEntity[],
componentName: string,
owner: string,
@@ -78,7 +78,6 @@ function generateEntities(
metadata: {
...e.metadata,
name: componentName,
namespace: e.metadata?.namespace ?? 'default',
},
spec: {
...e.spec,