From fbe88c29e67eb9c387deed1a33ed314328521de9 Mon Sep 17 00:00:00 2001 From: Thomas Moerkerken <1309462+moerketh@users.noreply.github.com> Date: Tue, 16 Apr 2024 09:41:58 +0200 Subject: [PATCH] fix(datasource/bicep): suppress resourceFunctions (#28379) --- .../azure-bicep-resource/index.spec.ts | 61 ++++++++++++++----- .../datasource/azure-bicep-resource/schema.ts | 8 +-- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/lib/modules/datasource/azure-bicep-resource/index.spec.ts b/lib/modules/datasource/azure-bicep-resource/index.spec.ts index 4afbff7d53..0b1dff2be1 100644 --- a/lib/modules/datasource/azure-bicep-resource/index.spec.ts +++ b/lib/modules/datasource/azure-bicep-resource/index.spec.ts @@ -28,7 +28,7 @@ describe('modules/datasource/azure-bicep-resource/index', () => { expect(result).toBeNull(); }); - it('should return versions when package is a function', async () => { + it('should return null when package is a function', async () => { httpMock .scope(gitHubHost) .get(indexPath) @@ -57,23 +57,10 @@ describe('modules/datasource/azure-bicep-resource/index', () => { const azureBicepResourceDatasource = new AzureBicepResourceDatasource(); const result = await azureBicepResourceDatasource.getReleases({ - packageName: 'Microsoft.Billing/billingAccounts', + packageName: 'unknown', }); - expect(result).toEqual({ - releases: [ - { - version: '2019-10-01-preview', - changelogUrl: - 'https://learn.microsoft.com/en-us/azure/templates/microsoft.billing/change-log/billingaccounts#2019-10-01-preview', - }, - { - version: '2020-05-01', - changelogUrl: - 'https://learn.microsoft.com/en-us/azure/templates/microsoft.billing/change-log/billingaccounts#2020-05-01', - }, - ], - }); + expect(result).toBeNull(); }); it('should return versions when package is a resource', async () => { @@ -117,4 +104,46 @@ describe('modules/datasource/azure-bicep-resource/index', () => { ], }); }); + + it('should return versions when package is a resource and a function', async () => { + httpMock + .scope(gitHubHost) + .get(indexPath) + .reply( + 200, + codeBlock` + { + "resources": { + "Microsoft.OperationalInsights/workspaces@2023-09-01": { + "$ref": "operationalinsights/microsoft.operationalinsights/2023-09-01/types.json#/31" + } + }, + "resourceFunctions": { + "microsoft.operationalinsights/workspaces": { + "2015-03-20": [ + { + "$ref": "operationalinsights/workspaces/2015-03-20/types.json#/304" + } + ] + } + } + } + `, + ); + + const azureBicepResourceDatasource = new AzureBicepResourceDatasource(); + const result = await azureBicepResourceDatasource.getReleases({ + packageName: 'Microsoft.OperationalInsights/workspaces', + }); + + expect(result).toEqual({ + releases: [ + { + version: '2023-09-01', + changelogUrl: + 'https://learn.microsoft.com/en-us/azure/templates/microsoft.operationalinsights/change-log/workspaces#2023-09-01', + }, + ], + }); + }); }); diff --git a/lib/modules/datasource/azure-bicep-resource/schema.ts b/lib/modules/datasource/azure-bicep-resource/schema.ts index 70dd2938f5..c94db6faea 100644 --- a/lib/modules/datasource/azure-bicep-resource/schema.ts +++ b/lib/modules/datasource/azure-bicep-resource/schema.ts @@ -3,9 +3,8 @@ import { z } from 'zod'; export const BicepResourceVersionIndex = z .object({ resources: z.record(z.string(), z.unknown()), - resourceFunctions: z.record(z.string(), z.record(z.string(), z.unknown())), }) - .transform(({ resources, resourceFunctions }) => { + .transform(({ resources }) => { const releaseMap = new Map<string, string[]>(); for (const resourceReference of Object.keys(resources)) { @@ -15,11 +14,6 @@ export const BicepResourceVersionIndex = z releaseMap.set(type, versions); } - for (const [type, versionMap] of Object.entries(resourceFunctions)) { - const versions = Object.keys(versionMap); - releaseMap.set(type, versions); - } - return Object.fromEntries(releaseMap); }); -- GitLab