|
| 1 | +import {KonaDistribution} from '../../src/distributions/kona/installer'; |
| 2 | + |
| 3 | +import manifestData from '../data/kona.json'; |
| 4 | + |
| 5 | +function mockDistr( |
| 6 | + version: string, |
| 7 | + os: string, |
| 8 | + arch: string, |
| 9 | + packageType: string |
| 10 | +): KonaDistribution { |
| 11 | + const distribution = new KonaDistribution({ |
| 12 | + version: version, |
| 13 | + architecture: arch, |
| 14 | + packageType: packageType, |
| 15 | + checkLatest: false |
| 16 | + }); |
| 17 | + |
| 18 | + distribution['getOs'] = () => os; |
| 19 | + distribution['fetchReleaseInfo'] = async () => manifestData; |
| 20 | + |
| 21 | + return distribution; |
| 22 | +} |
| 23 | + |
| 24 | +describe('Check getAvailableReleases', () => { |
| 25 | + it.each([ |
| 26 | + ['8', 'linux', 'aarch64', 'linux-aarch64'], |
| 27 | + ['8.0.19', 'macos', 'x86_64', 'macosx-x86_64'], |
| 28 | + ['11', 'linux', 'x86_64', 'linux-x86_64'], |
| 29 | + ['11.0.24', 'macos', 'aarch64', 'macosx-aarch64'], |
| 30 | + ['17.0.12', 'windows', 'x86_64', 'windows-x86_64'] |
| 31 | + ])( |
| 32 | + 'should get releases with the specified version "%s", OS "%s" and arch "%s"', |
| 33 | + async ( |
| 34 | + version: string, |
| 35 | + os: string, |
| 36 | + arch: string, |
| 37 | + expectedPattern: string |
| 38 | + ) => { |
| 39 | + const distribution = mockDistr(version, os, arch, 'jdk'); |
| 40 | + |
| 41 | + const releases = await distribution['getAvailableReleases'](); |
| 42 | + expect(releases).not.toBeNull(); |
| 43 | + expect(releases.length).toBe(3); |
| 44 | + releases.forEach((release, index) => |
| 45 | + expect(releases[index].downloadUrl).toContain(expectedPattern) |
| 46 | + ); |
| 47 | + } |
| 48 | + ); |
| 49 | +}); |
| 50 | + |
| 51 | +describe('Check findPackageForDownload', () => { |
| 52 | + it.each([ |
| 53 | + [ |
| 54 | + '8', |
| 55 | + 'linux', |
| 56 | + 'aarch64', |
| 57 | + 'https://github.com/Tencent/TencentKona-8/releases/download/8.0.19-GA/TencentKona8.0.19.b1_jdk_linux-aarch64_8u422.tar.gz' |
| 58 | + ], |
| 59 | + [ |
| 60 | + '8.0.19', |
| 61 | + 'linux', |
| 62 | + 'x86_64', |
| 63 | + 'https://github.com/Tencent/TencentKona-8/releases/download/8.0.19-GA/TencentKona8.0.19.b1_jdk_linux-x86_64_8u422.tar.gz' |
| 64 | + ], |
| 65 | + [ |
| 66 | + '8.0.19', |
| 67 | + 'macos', |
| 68 | + 'aarch64', |
| 69 | + 'https://github.com/Tencent/TencentKona-8/releases/download/8.0.19-GA/TencentKona8.0.19.b1_jdk_macosx-aarch64_8u422_notarized.tar.gz' |
| 70 | + ], |
| 71 | + [ |
| 72 | + '8.0.19', |
| 73 | + 'macos', |
| 74 | + 'x86_64', |
| 75 | + 'https://github.com/Tencent/TencentKona-8/releases/download/8.0.19-GA/TencentKona8.0.19.b1_jdk_macosx-x86_64_8u422_notarized.tar.gz' |
| 76 | + ], |
| 77 | + [ |
| 78 | + '8.0.19', |
| 79 | + 'windows', |
| 80 | + 'x86_64', |
| 81 | + 'https://github.com/Tencent/TencentKona-8/releases/download/8.0.19-GA/TencentKona8.0.19.b1_jdk_windows-x86_64_8u422_signed.zip' |
| 82 | + ], |
| 83 | + |
| 84 | + [ |
| 85 | + '11', |
| 86 | + 'linux', |
| 87 | + 'aarch64', |
| 88 | + 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.24/TencentKona-11.0.24.b1-jdk_linux-aarch64.tar.gz' |
| 89 | + ], |
| 90 | + [ |
| 91 | + '11.0.24', |
| 92 | + 'linux', |
| 93 | + 'x86_64', |
| 94 | + 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.24/TencentKona-11.0.24.b1-jdk_linux-x86_64.tar.gz' |
| 95 | + ], |
| 96 | + [ |
| 97 | + '11.0.24', |
| 98 | + 'macos', |
| 99 | + 'aarch64', |
| 100 | + 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.24/TencentKona-11.0.24.b1_jdk_macosx-aarch64_notarized.tar.gz' |
| 101 | + ], |
| 102 | + [ |
| 103 | + '11.0.24', |
| 104 | + 'macos', |
| 105 | + 'x86_64', |
| 106 | + 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.24/TencentKona-11.0.24.b1_jdk_macosx-x86_64_notarized.tar.gz' |
| 107 | + ], |
| 108 | + [ |
| 109 | + '11.0.24', |
| 110 | + 'windows', |
| 111 | + 'x86_64', |
| 112 | + 'https://github.com/Tencent/TencentKona-11/releases/download/kona11.0.24/TencentKona-11.0.24.b1_jdk_windows-x86_64_signed.zip' |
| 113 | + ], |
| 114 | + |
| 115 | + [ |
| 116 | + '17', |
| 117 | + 'linux', |
| 118 | + 'aarch64', |
| 119 | + 'https://github.com/Tencent/TencentKona-17/releases/download/TencentKona-17.0.12/TencentKona-17.0.12.b1-jdk_linux-aarch64.tar.gz' |
| 120 | + ], |
| 121 | + [ |
| 122 | + '17.0.12', |
| 123 | + 'linux', |
| 124 | + 'x86_64', |
| 125 | + 'https://github.com/Tencent/TencentKona-17/releases/download/TencentKona-17.0.12/TencentKona-17.0.12.b1-jdk_linux-x86_64.tar.gz' |
| 126 | + ], |
| 127 | + [ |
| 128 | + '17.0.12', |
| 129 | + 'macos', |
| 130 | + 'aarch64', |
| 131 | + 'https://github.com/Tencent/TencentKona-17/releases/download/TencentKona-17.0.12/TencentKona-17.0.12.b1_jdk_macosx-aarch64_notarized.tar.gz' |
| 132 | + ], |
| 133 | + [ |
| 134 | + '17.0.12', |
| 135 | + 'macos', |
| 136 | + 'x86_64', |
| 137 | + 'https://github.com/Tencent/TencentKona-17/releases/download/TencentKona-17.0.12/TencentKona-17.0.12.b1_jdk_macosx-x86_64_notarized.tar.gz' |
| 138 | + ], |
| 139 | + [ |
| 140 | + '17.0.12', |
| 141 | + 'windows', |
| 142 | + 'x86_64', |
| 143 | + 'https://github.com/Tencent/TencentKona-17/releases/download/TencentKona-17.0.12/TencentKona-17.0.12.b1_jdk_windows-x86_64_signed.zip' |
| 144 | + ] |
| 145 | + ])( |
| 146 | + 'should return the download URL with the specified version "%s", OS "%s" and arch "%s"', |
| 147 | + async (version: string, os: string, arch: string, expectedUrl: string) => { |
| 148 | + const distribution = mockDistr(version, os, arch, 'jdk'); |
| 149 | + |
| 150 | + const availableRelease = await distribution['findPackageForDownload']( |
| 151 | + version |
| 152 | + ); |
| 153 | + expect(availableRelease).not.toBeNull(); |
| 154 | + expect(availableRelease.url).toBe(expectedUrl); |
| 155 | + } |
| 156 | + ); |
| 157 | +}); |
| 158 | + |
| 159 | +describe('No release is found', () => { |
| 160 | + it.each([ |
| 161 | + ['8', 'linux', 'x86'], |
| 162 | + ['17', 'solaris', 'x86_64'], |
| 163 | + ['21', 'linux', 'x86_64'] |
| 164 | + ])( |
| 165 | + `should throw an error due to no release with the specified version "%s", os "%s" and arch "%s"`, |
| 166 | + async (version: string, os: string, arch: string) => { |
| 167 | + const distribution = mockDistr(version, os, arch, 'jdk'); |
| 168 | + |
| 169 | + await expect( |
| 170 | + distribution['findPackageForDownload'](version) |
| 171 | + ).rejects.toThrow( |
| 172 | + `No Kona release for the specified version "${version}" on OS "${os}" and arch "${arch}".` |
| 173 | + ); |
| 174 | + } |
| 175 | + ); |
| 176 | +}); |
| 177 | + |
| 178 | +describe('The package type must be jdk', () => { |
| 179 | + it('should throw an error due to the specified package type is not jdk', async () => { |
| 180 | + const version = '8.0.19'; |
| 181 | + const os = 'linux'; |
| 182 | + const arch = 'x86_64'; |
| 183 | + const distribution = mockDistr(version, os, arch, 'jre'); |
| 184 | + |
| 185 | + await expect( |
| 186 | + distribution['findPackageForDownload'](version) |
| 187 | + ).rejects.toThrow('Kona provides jdk only'); |
| 188 | + }); |
| 189 | +}); |
0 commit comments