From c40aa8798c437fd8b89ac84da0a4b916bd5d4bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 10 Sep 2024 17:36:29 +0200 Subject: [PATCH] empty setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../catalog-client/api-report-testUtils.md | 101 +++++++++++++ packages/catalog-client/package.json | 20 ++- packages/catalog-client/src/testUtils.ts | 17 +++ .../src/testUtils/InMemoryCatalogClient.ts | 138 ++++++++++++++++++ .../catalog-client/src/testUtils/index.ts | 17 +++ plugins/catalog-node/api-report-testUtils.md | 7 + plugins/catalog-node/package.json | 4 + plugins/catalog-node/src/testUtils.ts | 17 +++ .../src/testUtils/catalogServiceMock.ts | 32 ++++ plugins/catalog-node/src/testUtils/index.ts | 17 +++ 10 files changed, 366 insertions(+), 4 deletions(-) create mode 100644 packages/catalog-client/api-report-testUtils.md create mode 100644 packages/catalog-client/src/testUtils.ts create mode 100644 packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts create mode 100644 packages/catalog-client/src/testUtils/index.ts create mode 100644 plugins/catalog-node/api-report-testUtils.md create mode 100644 plugins/catalog-node/src/testUtils.ts create mode 100644 plugins/catalog-node/src/testUtils/catalogServiceMock.ts create mode 100644 plugins/catalog-node/src/testUtils/index.ts diff --git a/packages/catalog-client/api-report-testUtils.md b/packages/catalog-client/api-report-testUtils.md new file mode 100644 index 0000000000..f78c6de5c9 --- /dev/null +++ b/packages/catalog-client/api-report-testUtils.md @@ -0,0 +1,101 @@ +## API Report File for "@backstage/catalog-client" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { AddLocationRequest } from '@backstage/catalog-client'; +import { AddLocationResponse } from '@backstage/catalog-client'; +import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogRequestOptions } from '@backstage/catalog-client'; +import { CompoundEntityRef } from '@backstage/catalog-model'; +import { Entity } from '@backstage/catalog-model'; +import { GetEntitiesByRefsRequest } from '@backstage/catalog-client'; +import { GetEntitiesByRefsResponse } from '@backstage/catalog-client'; +import { GetEntitiesRequest } from '@backstage/catalog-client'; +import { GetEntitiesResponse } from '@backstage/catalog-client'; +import { GetEntityAncestorsRequest } from '@backstage/catalog-client'; +import { GetEntityAncestorsResponse } from '@backstage/catalog-client'; +import { GetEntityFacetsRequest } from '@backstage/catalog-client'; +import { GetEntityFacetsResponse } from '@backstage/catalog-client'; +import { Location as Location_2 } from '@backstage/catalog-client'; +import { QueryEntitiesRequest } from '@backstage/catalog-client'; +import { QueryEntitiesResponse } from '@backstage/catalog-client'; +import { ValidateEntityResponse } from '@backstage/catalog-client'; + +// @public (undocumented) +export class InMemoryCatalogClient implements CatalogApi { + // (undocumented) + addLocation( + _location: AddLocationRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getEntities( + _request?: GetEntitiesRequest | undefined, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getEntitiesByRefs( + _request: GetEntitiesByRefsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getEntityAncestors( + _request: GetEntityAncestorsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getEntityByRef( + _entityRef: string | CompoundEntityRef, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getEntityFacets( + _request: GetEntityFacetsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getLocationByEntity( + _entityRef: string | CompoundEntityRef, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getLocationById( + _id: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + getLocationByRef( + _locationRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + queryEntities( + _request?: QueryEntitiesRequest | undefined, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + refreshEntity( + _entityRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + removeEntityByUid( + _uid: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + removeLocationById( + _id: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; + // (undocumented) + validateEntity( + _entity: Entity, + _locationRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise; +} + +// (No @packageDocumentation comment for this package) +``` diff --git a/packages/catalog-client/package.json b/packages/catalog-client/package.json index d09a85efbc..4119614503 100644 --- a/packages/catalog-client/package.json +++ b/packages/catalog-client/package.json @@ -6,10 +6,7 @@ "role": "common-library" }, "publishConfig": { - "access": "public", - "main": "dist/index.cjs.js", - "module": "dist/index.esm.js", - "types": "dist/index.d.ts" + "access": "public" }, "keywords": [ "backstage" @@ -22,8 +19,23 @@ }, "license": "Apache-2.0", "sideEffects": false, + "exports": { + ".": "./src/index.ts", + "./testUtils": "./src/testUtils.ts", + "./package.json": "./package.json" + }, "main": "src/index.ts", "types": "src/index.ts", + "typesVersions": { + "*": { + "testUtils": [ + "src/testUtils.ts" + ], + "package.json": [ + "package.json" + ] + } + }, "files": [ "dist" ], diff --git a/packages/catalog-client/src/testUtils.ts b/packages/catalog-client/src/testUtils.ts new file mode 100644 index 0000000000..15017c7fa0 --- /dev/null +++ b/packages/catalog-client/src/testUtils.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 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. + */ + +export { InMemoryCatalogClient } from './testUtils/InMemoryCatalogClient'; diff --git a/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts new file mode 100644 index 0000000000..c5ceafcd46 --- /dev/null +++ b/packages/catalog-client/src/testUtils/InMemoryCatalogClient.ts @@ -0,0 +1,138 @@ +/* + * Copyright 2024 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 { + AddLocationRequest, + AddLocationResponse, + CatalogApi, + CatalogRequestOptions, + GetEntitiesByRefsRequest, + GetEntitiesByRefsResponse, + GetEntitiesRequest, + GetEntitiesResponse, + GetEntityAncestorsRequest, + GetEntityAncestorsResponse, + GetEntityFacetsRequest, + GetEntityFacetsResponse, + Location, + QueryEntitiesRequest, + QueryEntitiesResponse, + ValidateEntityResponse, +} from '@backstage/catalog-client'; +import { CompoundEntityRef, Entity } from '@backstage/catalog-model'; +import { NotImplementedError } from '@backstage/errors'; + +/** @public */ +export class InMemoryCatalogClient implements CatalogApi { + getEntities( + _request?: GetEntitiesRequest | undefined, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getEntitiesByRefs( + _request: GetEntitiesByRefsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + queryEntities( + _request?: QueryEntitiesRequest | undefined, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getEntityAncestors( + _request: GetEntityAncestorsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getEntityByRef( + _entityRef: string | CompoundEntityRef, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + removeEntityByUid( + _uid: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + refreshEntity( + _entityRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getEntityFacets( + _request: GetEntityFacetsRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getLocationById( + _id: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getLocationByRef( + _locationRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + addLocation( + _location: AddLocationRequest, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + removeLocationById( + _id: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + getLocationByEntity( + _entityRef: string | CompoundEntityRef, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } + + validateEntity( + _entity: Entity, + _locationRef: string, + _options?: CatalogRequestOptions | undefined, + ): Promise { + throw new NotImplementedError('Method not implemented.'); + } +} diff --git a/packages/catalog-client/src/testUtils/index.ts b/packages/catalog-client/src/testUtils/index.ts new file mode 100644 index 0000000000..a28adac13d --- /dev/null +++ b/packages/catalog-client/src/testUtils/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 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. + */ + +export { InMemoryCatalogClient } from './InMemoryCatalogClient'; diff --git a/plugins/catalog-node/api-report-testUtils.md b/plugins/catalog-node/api-report-testUtils.md new file mode 100644 index 0000000000..23c759fa9a --- /dev/null +++ b/plugins/catalog-node/api-report-testUtils.md @@ -0,0 +1,7 @@ +## API Report File for "@backstage/plugin-catalog-node" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/catalog-node/package.json b/plugins/catalog-node/package.json index 32cb210f97..eb920bff93 100644 --- a/plugins/catalog-node/package.json +++ b/plugins/catalog-node/package.json @@ -26,6 +26,7 @@ "exports": { ".": "./src/index.ts", "./alpha": "./src/alpha.ts", + "./testUtils": "./src/testUtils.ts", "./package.json": "./package.json" }, "main": "src/index.ts", @@ -35,6 +36,9 @@ "alpha": [ "src/alpha.ts" ], + "testUtils": [ + "src/testUtils.ts" + ], "package.json": [ "package.json" ] diff --git a/plugins/catalog-node/src/testUtils.ts b/plugins/catalog-node/src/testUtils.ts new file mode 100644 index 0000000000..96551ee7b7 --- /dev/null +++ b/plugins/catalog-node/src/testUtils.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 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. + */ + +export * from './testUtils'; diff --git a/plugins/catalog-node/src/testUtils/catalogServiceMock.ts b/plugins/catalog-node/src/testUtils/catalogServiceMock.ts new file mode 100644 index 0000000000..080609986c --- /dev/null +++ b/plugins/catalog-node/src/testUtils/catalogServiceMock.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2024 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 { createServiceFactory } from '@backstage/backend-plugin-api'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils'; + +/** @public */ +export function catalogServiceMock() {} + +/** @public */ +export namespace catalogServiceMock { + export const factory = () => + createServiceFactory({ + service: catalogServiceRef, + deps: {}, + factory: () => new InMemoryCatalogClient(), + }); +} diff --git a/plugins/catalog-node/src/testUtils/index.ts b/plugins/catalog-node/src/testUtils/index.ts new file mode 100644 index 0000000000..71c20fa7f4 --- /dev/null +++ b/plugins/catalog-node/src/testUtils/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 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. + */ + +export { type catalogServiceMock } from './catalogServiceMock';