Files
renovate/lib/modules/datasource/deb/url.spec.ts
Sebastian Poxhofer 03baf6ee4a test(noNewURL): add new rule enforcing parseUrl() from 'lib/util/url.ts' (#43247)
* test(noNewURL): add new rule enforcing parseUrl() from 'lib/util/url.ts'

* replace newURL with parseUrl

* remove non-null assertions marks if appropiate

* test: add additional tests

* test: add additional tests and ignore where it makes sense

* implement suggestions

* test: further improve coverage

* apply suggestion
2026-05-13 16:23:10 +00:00

80 lines
2.6 KiB
TypeScript

import * as httpMock from '~test/http-mock.ts';
import { Http } from '../../../util/http/index.ts';
import {
checkIfModified,
constructComponentUrls,
getPackageUrl,
} from './url.ts';
describe('modules/datasource/deb/url', () => {
describe('constructComponentUrls', () => {
it('constructs URLs correctly from registry URL with suite', () => {
const registryUrl =
'https://deb.debian.org/debian?suite=stable&components=main,contrib&binaryArch=amd64';
const expectedUrls = [
'https://deb.debian.org/debian/dists/stable/main/binary-amd64',
'https://deb.debian.org/debian/dists/stable/contrib/binary-amd64',
];
const componentUrls = constructComponentUrls(registryUrl);
expect(componentUrls).toEqual(expectedUrls);
});
it('constructs URLs correctly from registry URL with deprecated release', () => {
const registryUrl =
'https://deb.debian.org/debian?release=bullseye&components=main,contrib&binaryArch=amd64';
const expectedUrls = [
'https://deb.debian.org/debian/dists/bullseye/main/binary-amd64',
'https://deb.debian.org/debian/dists/bullseye/contrib/binary-amd64',
];
const componentUrls = constructComponentUrls(registryUrl);
expect(componentUrls).toEqual(expectedUrls);
});
it('throws an error if required parameters are missing', () => {
const registryUrl =
'https://deb.debian.org/debian?components=main,contrib';
expect(() => constructComponentUrls(registryUrl)).toThrow(
'Missing required query parameter',
);
});
it('returns empty array for invalid registry URL', () => {
expect(constructComponentUrls('not-a-valid-url')).toEqual([]);
});
});
describe('checkIfModified', () => {
const debBaseUrl = 'http://deb.debian.org';
it('should return true for different status code', async () => {
httpMock
.scope(debBaseUrl)
.head(getPackageUrl('', 'stable', 'non-free', 'amd64'))
.reply(200);
await expect(
checkIfModified(
getPackageUrl(debBaseUrl, 'stable', 'non-free', 'amd64'),
new Date(),
new Http('default'),
),
).resolves.toBe(true);
});
it('should return true if request failed', async () => {
httpMock
.scope(debBaseUrl)
.head(getPackageUrl('', 'stable', 'non-free', 'amd64'))
.replyWithError('Unexpected Error');
await expect(
checkIfModified(
getPackageUrl(debBaseUrl, 'stable', 'non-free', 'amd64'),
new Date(),
new Http('default'),
),
).resolves.toBe(true);
});
});
});