|
| 1 | +import { describe, it } from "node:test"; |
| 2 | +import assert from "node:assert"; |
| 3 | +import { deepMerge } from "../../utils/merge-yamls.js"; |
| 4 | +import { getNormalizedPluginMergeKey } from "../../utils/plugin-metadata.js"; |
| 5 | + |
| 6 | +/** |
| 7 | + * Tests the merge behavior used when user dynamic-plugins config does not exist: |
| 8 | + * auth config (e.g. keycloak) is merged with metadata config using normalized plugin key. |
| 9 | + * Result must have exactly one entry per logical plugin; metadata (source) wins so OCI URL is kept. |
| 10 | + */ |
| 11 | +describe("dynamic-plugins merge (no user config path)", () => { |
| 12 | + it("yields one keycloak plugin with OCI package when auth has local path and metadata has OCI", () => { |
| 13 | + const authPlugins: Record<string, unknown> = { |
| 14 | + plugins: [ |
| 15 | + { |
| 16 | + package: |
| 17 | + "./dynamic-plugins/dist/backstage-community-plugin-catalog-backend-module-keycloak-dynamic", |
| 18 | + disabled: false, |
| 19 | + pluginConfig: {}, |
| 20 | + }, |
| 21 | + ], |
| 22 | + includes: ["dynamic-plugins.default.yaml"], |
| 23 | + }; |
| 24 | + const metadataConfig: Record<string, unknown> = { |
| 25 | + plugins: [ |
| 26 | + { |
| 27 | + package: |
| 28 | + "oci://ghcr.io/redhat-developer/rhdh-plugin-export-overlays/backstage-community-plugin-catalog-backend-module-keycloak:pr_1980__3.16.0!backstage-community-plugin-catalog-backend-module-keycloak", |
| 29 | + disabled: false, |
| 30 | + pluginConfig: { catalog: { providers: { keycloakOrg: {} } } }, |
| 31 | + }, |
| 32 | + ], |
| 33 | + }; |
| 34 | + const merged = deepMerge(authPlugins, metadataConfig, { |
| 35 | + arrayMergeStrategy: { |
| 36 | + byKey: "package", |
| 37 | + normalizeKey: (item) => |
| 38 | + getNormalizedPluginMergeKey(item as Record<string, unknown>), |
| 39 | + }, |
| 40 | + }); |
| 41 | + const plugins = merged.plugins as Array<{ package?: string }>; |
| 42 | + assert.strictEqual( |
| 43 | + plugins.length, |
| 44 | + 1, |
| 45 | + "merged config must have exactly one keycloak plugin", |
| 46 | + ); |
| 47 | + assert.ok( |
| 48 | + plugins[0].package?.startsWith("oci://"), |
| 49 | + "metadata (OCI) must win over auth local path", |
| 50 | + ); |
| 51 | + }); |
| 52 | +}); |
0 commit comments