Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdev03 committed Jul 7, 2024
1 parent d57eaba commit 762d116
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
65 changes: 56 additions & 9 deletions lib/modules/datasource/deb/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,63 @@ describe('modules/datasource/deb/index', () => {
});
});

describe.skip('extract', () => {
describe('extract', () => {
it('should throw error for unsupported compression', async () => {
expect(
async () =>
await DebDatasource.extract(
fixturePackagesArchivePath,
'xz',
extractedPackageFile,
),
).toThrow();
await expect(
DebDatasource.extract(
fixturePackagesArchivePath,
'xz',
extractedPackageFile,
),
).rejects.toThrow('Unsupported compression standard');
});
});

describe('downloadAndExtractPackage', () => {
beforeEach(() => {
httpMock
.scope('http://ftp.debian.org')
.get('/debian/dists/bullseye/main/binary-amd64/Packages.gz')
.replyWithFile(200, fixturePackagesArchivePath2);
});

it('should throw error for unsupported compression', async () => {
DebDatasource.extract = jest.fn().mockRejectedValueOnce(new Error());
await expect(
debDatasource.downloadAndExtractPackage(
'http://ftp.debian.org/debian/dists/bullseye/main/binary-amd64',
),
).rejects.toThrow(`No compression standard worked for `);
});
});

describe('checkIfModified', () => {
it('should return true for different status code', async () => {
httpMock
.scope('http://ftp.debian.org')
.head('/debian/dists/stable/non-free/binary-amd64/Packages.gz')
.reply(200);

await expect(
debDatasource.checkIfModified(
'http://ftp.debian.org/debian/dists/stable/non-free/binary-amd64/Packages.gz',
new Date(),
),
).resolves.toBe(true);
});

it('should return true if request failed', async () => {
httpMock
.scope('http://ftp.debian.org')
.head('/debian/dists/stable/non-free/binary-amd64/Packages.gz')
.replyWithError('Unexpected Error');

await expect(
debDatasource.checkIfModified(
'http://ftp.debian.org/debian/dists/stable/non-free/binary-amd64/Packages.gz',
new Date(),
),
).resolves.toBe(true);
});
});
});
13 changes: 10 additions & 3 deletions lib/modules/datasource/deb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ export class DebDatasource extends Datasource {
await fs.rmCache(compressedFile);
}
}
return { extractedFile, lastTimestamp: lastTimestamp! };

if (!lastTimestamp) {
//extracting went wrong
break;
}

return { extractedFile, lastTimestamp };
}

throw new Error(`No compression standard worked for ${componentUrl}`);
Expand Down Expand Up @@ -325,8 +331,9 @@ export class DebDatasource extends Datasource {

const getReleaseParam = (url: URL): string => {
for (const param of OPTIONAL_PARAMS) {
if (url.searchParams.has(param)) {
return url.searchParams.get(param) ?? '';
const paramValue = url.searchParams.get(param);
if (paramValue !== null) {
return paramValue;
}
}
throw new Error(
Expand Down

0 comments on commit 762d116

Please sign in to comment.