fix(datasource/bicep): suppress resourceFunctions ()

pull/28435/head 37.301.1
Thomas Moerkerken 2024-04-16 09:41:58 +02:00 committed by GitHub
parent c3635f75ff
commit fbe88c29e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 23 deletions
lib/modules/datasource/azure-bicep-resource

View File

@ -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',
},
],
});
});
});

View File

@ -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);
});