scaffolder-backend: test hasTag rule
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2023 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 { hasTag } from './rules';
|
||||
|
||||
describe('hasTag', () => {
|
||||
describe('apply', () => {
|
||||
it('returns false when the tag is not present', () => {
|
||||
expect(
|
||||
hasTag.apply(
|
||||
{
|
||||
'backstage:accessControl': {
|
||||
tags: ['foo', 'bar'],
|
||||
},
|
||||
},
|
||||
{
|
||||
tag: 'baz',
|
||||
},
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false when accessControl is missing', () => {
|
||||
expect(
|
||||
hasTag.apply(
|
||||
{},
|
||||
{
|
||||
tag: 'baz',
|
||||
},
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false when tags is an empty array', () => {
|
||||
expect(
|
||||
hasTag.apply(
|
||||
{
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
'backstage:accessControl': {
|
||||
tags: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
tag: 'baz',
|
||||
},
|
||||
),
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns true when the tag is present', () => {
|
||||
expect(
|
||||
hasTag.apply(
|
||||
{
|
||||
'backstage:accessControl': {
|
||||
tags: ['foo', 'bar'],
|
||||
},
|
||||
},
|
||||
{
|
||||
tag: 'bar',
|
||||
},
|
||||
),
|
||||
).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -22,16 +22,16 @@ import {
|
||||
} from '@backstage/plugin-scaffolder-common';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const createScaffolderStepPermissionRule = makeCreatePermissionRule<
|
||||
export const createScaffolderPermissionRule = makeCreatePermissionRule<
|
||||
TemplateEntityStepV1beta3 | TemplateParameter,
|
||||
{},
|
||||
typeof RESOURCE_TYPE_SCAFFOLDER_TEMPLATE
|
||||
>();
|
||||
|
||||
const hasTag = createScaffolderStepPermissionRule({
|
||||
export const hasTag = createScaffolderPermissionRule({
|
||||
name: 'HAS_TAG',
|
||||
resourceType: RESOURCE_TYPE_SCAFFOLDER_TEMPLATE,
|
||||
description: 'Match a scaffolder step with the given tag',
|
||||
description: `Match parameters or steps with the given tag`,
|
||||
paramsSchema: z.object({
|
||||
tag: z.string().describe('Name of the tag to match on'),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user