1
0
mirror of https://github.com/actions/setup-java.git synced 2026-04-19 17:18:40 +08:00

Refactor error handling and improve test logging for installers (#989)

* Refactor error handling for version not found cases across multiple installers

* Mock core.error in tests to suppress error logs

* fix(graalvm): improve error messages for EA version not found scenarios

* refactor(tests): update error messages for version not found scenarios

* fix(graalvm): enhance error messages for version not found scenarios

* fix(graalvm): improve error messages for version not found scenarios with updated download URL

* fix(graalvm): improve error handling for EA version not found scenarios with clearer messages
This commit is contained in:
Chiranjib Swain
2026-04-13 23:14:45 +05:30
committed by GitHub
parent 1d018f9b8b
commit 0756542bc5
34 changed files with 414 additions and 176 deletions

View File

@@ -42,6 +42,7 @@ beforeAll(() => {
describe('GraalVMDistribution', () => {
let distribution: GraalVMDistribution;
let mockHttpClient: jest.Mocked<http.HttpClient>;
let spyCoreError: jest.SpyInstance;
const defaultOptions: JavaInstallerOptions = {
version: '17',
@@ -59,6 +60,10 @@ describe('GraalVMDistribution', () => {
(distribution as any).http = mockHttpClient;
(util.getDownloadArchiveExtension as jest.Mock).mockReturnValue('tar.gz');
// Mock core.error to suppress error logs
spyCoreError = jest.spyOn(core, 'error');
spyCoreError.mockImplementation(() => {});
});
afterAll(() => {
@@ -348,11 +353,19 @@ describe('GraalVMDistribution', () => {
} as http.HttpClientResponse;
mockHttpClient.head.mockResolvedValue(mockResponse);
// Verify the error is thrown with the expected message
await expect(
(distribution as any).findPackageForDownload('17.0.99')
).rejects.toThrow(
'Could not find GraalVM for SemVer 17.0.99. Please check if this version is available at https://download.oracle.com/graalvm'
);
).rejects.toThrow("No matching version found for SemVer '17.0.99'");
// Verify distribution info is included
await expect(
(distribution as any).findPackageForDownload('17.0.99')
).rejects.toThrow('GraalVM');
// Verify the hint about checking the base URL is included
await expect(
(distribution as any).findPackageForDownload('17.0.99')
).rejects.toThrow('https://www.graalvm.org/downloads/');
});
it('should throw error for unauthorized access (401)', async () => {
@@ -496,12 +509,19 @@ describe('GraalVMDistribution', () => {
await expect(
(distribution as any).findPackageForDownload('23')
).rejects.toThrow("Unable to find latest version for '23-ea'");
).rejects.toThrow("No matching version found for SemVer '23-ea'");
// Verify error logging
expect(core.error).toHaveBeenCalledWith(
'Available versions: 23-ea-20240716'
await expect(
(distribution as any).findPackageForDownload('23')
).rejects.toThrow(
'Note: No EA build is marked as latest for this version.'
);
await expect(
(distribution as any).findPackageForDownload('23')
).rejects.toThrow('23-ea-20240716');
// Verify error logging - removed as we now use the helper method which doesn't call core.error
});
it('should throw error when no matching file for architecture in EA build', async () => {
@@ -708,11 +728,19 @@ describe('GraalVMDistribution', () => {
await expect(
(distribution as any).findEABuildDownloadUrl('23-ea')
).rejects.toThrow("Unable to find latest version for '23-ea'");
).rejects.toThrow("No matching version found for SemVer '23-ea'");
expect(core.error).toHaveBeenCalledWith(
'Available versions: 23-ea-20240716, 23-ea-20240709'
await expect(
(distribution as any).findEABuildDownloadUrl('23-ea')
).rejects.toThrow(
'Note: No EA build is marked as latest for this version.'
);
await expect(
(distribution as any).findEABuildDownloadUrl('23-ea')
).rejects.toThrow('23-ea-20240716');
// Verify error logging - removed as we now use the helper method which doesn't call core.error
});
it('should throw error when no matching file for architecture', async () => {