From e5655a806d0ed5efeba231b15ac821ddf8337bca Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Sun, 24 Nov 2024 11:39:21 -0300 Subject: [PATCH] refactor(maven): Fix types for util functions (#32702) --- lib/modules/datasource/maven/util.spec.ts | 30 ++++++----------------- lib/modules/datasource/maven/util.ts | 6 +---- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/lib/modules/datasource/maven/util.spec.ts b/lib/modules/datasource/maven/util.spec.ts index fb94fa28ea7cae..fc42f24610b2b7 100644 --- a/lib/modules/datasource/maven/util.spec.ts +++ b/lib/modules/datasource/maven/util.spec.ts @@ -1,8 +1,7 @@ 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, @@ -10,6 +9,8 @@ import { downloadS3Protocol, } from './util'; +const http = new Http('test'); + function httpError({ name, message = 'unknown error', @@ -46,16 +47,8 @@ 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({}); }); @@ -63,8 +56,7 @@ describe('modules/datasource/maven/util', () => { 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(); }); }); @@ -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'); }); }); diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index b521b99d53ab1d..d68d35757bdf01 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -307,12 +307,8 @@ export function getMavenUrl( export async function downloadMavenXml( http: Http, - pkgUrl: URL | null, + pkgUrl: URL, ): Promise { - if (!pkgUrl) { - return {}; - } - const protocol = pkgUrl.protocol; if (protocol === 'http:' || protocol === 'https:') {