Files
Arnaud Dezandee 914c55b03c refactor(terraform-module): replace interfaces with zod schemas and inline fixtures (#42399)
* refactor(terraform-module): extract getRegistryRepository to utils

* refactor(terraform-module): add zod schemas and validate service discovery

* refactor(terraform-module): use zod schemas in query methods and inline fixtures

* fix(terraform): update hash test to use valid service discovery response

* refactor(terraform-module): address review feedback

* style: biome lint fix

* refactor(terraform-module): address review feedback
2026-04-15 13:41:28 +00:00

121 lines
3.3 KiB
TypeScript

import { createSDBackendURL, getRegistryRepository } from './utils.ts';
describe('modules/datasource/terraform-module/utils', () => {
describe('createSDBackendURL', () => {
const defaultRegistryURL = 'https://registry.example.com';
it('returns URL with relative SD for modules', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'modules.v1',
{
'modules.v1': '/v1/modules/',
},
'hashicorp/consul/aws',
);
expect(result).toBe(
'https://registry.example.com/v1/modules/hashicorp/consul/aws',
);
});
it('returns URL with relative SD for providers', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'providers.v1',
{
'providers.v1': '/v1/providers/',
},
'hashicorp/azure',
);
expect(result).toBe(
'https://registry.example.com/v1/providers/hashicorp/azure',
);
});
it('returns URL with absolute SD for modules', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'modules.v1',
{
'modules.v1': 'https://other.example.com/v1/modules/',
},
'hashicorp/consul/aws',
);
expect(result).toBe(
'https://other.example.com/v1/modules/hashicorp/consul/aws',
);
});
it('returns URL with absolute SD for providers and missing trailing slash', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'providers.v1',
{
'providers.v1': 'https://other.example.com/providers',
},
'hashicorp/azure',
);
expect(result).toBe(
'https://other.example.com/providers/hashicorp/azure',
);
});
it('returns URL with with empty SD', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'providers.v1',
{
'providers.v1': '',
},
'hashicorp/azure',
);
expect(result).toBe('https://registry.example.com/hashicorp/azure');
});
it('returns URL with with missing SD', () => {
const result = createSDBackendURL(
defaultRegistryURL,
'providers.v1',
{},
'hashicorp/azure',
);
expect(result).toBe('https://registry.example.com/hashicorp/azure');
});
});
describe('getRegistryRepository', () => {
it('uses the configured registry URL for standard package names', () => {
expect(
getRegistryRepository(
'hashicorp/consul/aws',
'https://registry.terraform.io',
),
).toEqual({
registry: 'https://registry.terraform.io',
repository: 'hashicorp/consul/aws',
});
});
it('extracts the registry from packageName when it is embedded', () => {
expect(
getRegistryRepository(
'registry.terraform.io/hashicorp/consul/aws',
undefined,
),
).toEqual({
registry: 'https://registry.terraform.io',
repository: 'hashicorp/consul/aws',
});
});
it('normalizes an embedded registry without a scheme', () => {
expect(
getRegistryRepository('terraform.company.com/hashicorp/consul/aws', ''),
).toEqual({
registry: 'https://terraform.company.com',
repository: 'hashicorp/consul/aws',
});
});
});
});