Skip to content

Commit

Permalink
refactor(maven): Fix types for util functions (#32702)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Nov 24, 2024
1 parent 5367a7a commit e5655a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
30 changes: 8 additions & 22 deletions lib/modules/datasource/maven/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type Request from 'got/dist/source/core';
import { partial } from '../../../../test/util';
import { HOST_DISABLED } from '../../../constants/error-messages';
import { type Http, HttpError } from '../../../util/http';
import { parseUrl } from '../../../util/url';
import { Http, HttpError } from '../../../util/http';
import {
checkResource,
downloadHttpProtocol,
downloadMavenXml,
downloadS3Protocol,
} from './util';

const http = new Http('test');

function httpError({
name,
message = 'unknown error',
Expand Down Expand Up @@ -46,25 +47,16 @@ describe('modules/datasource/maven/util', () => {
describe('downloadMavenXml', () => {
it('returns empty object for unsupported protocols', async () => {
const res = await downloadMavenXml(
null as never, // #22198
parseUrl('unsupported://server.com/'),
);
expect(res).toEqual({});
});

it('returns empty object for invalid URLs', async () => {
const res = await downloadMavenXml(
null as never, // #22198
null,
http,
new URL('unsupported://server.com/'),
);
expect(res).toEqual({});
});
});

describe('downloadS3Protocol', () => {
it('returns null for non-S3 URLs', async () => {
// #22198
const res = await downloadS3Protocol(parseUrl('http://not-s3.com/')!);
const res = await downloadS3Protocol(new URL('http://not-s3.com/'));
expect(res).toBeNull();
});
});
Expand Down Expand Up @@ -114,18 +106,12 @@ describe('modules/datasource/maven/util', () => {

describe('checkResource', () => {
it('returns not found for unsupported protocols', async () => {
const res = await checkResource(
null as never, // #22198
'unsupported://server.com/',
);
const res = await checkResource(http, 'unsupported://server.com/');
expect(res).toBe('not-found');
});

it('returns error for invalid URLs', async () => {
const res = await checkResource(
null as never, // #22198
'not-a-valid-url',
);
const res = await checkResource(http, 'not-a-valid-url');
expect(res).toBe('error');
});
});
Expand Down
6 changes: 1 addition & 5 deletions lib/modules/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,8 @@ export function getMavenUrl(

export async function downloadMavenXml(
http: Http,
pkgUrl: URL | null,
pkgUrl: URL,
): Promise<MavenXml> {
if (!pkgUrl) {
return {};
}

const protocol = pkgUrl.protocol;

if (protocol === 'http:' || protocol === 'https:') {
Expand Down

0 comments on commit e5655a8

Please sign in to comment.