|
| 1 | +import {HttpClient} from '@actions/http-client'; |
| 2 | +import {DragonwellDistribution} from '../../src/distributions/dragonwell/installer'; |
| 3 | +import * as utils from '../../src/util'; |
| 4 | + |
| 5 | +import manifestData from '../data/dragonwell.json'; |
| 6 | + |
| 7 | +describe('getAvailableVersions', () => { |
| 8 | + let spyHttpClient: jest.SpyInstance; |
| 9 | + let spyUtilGetDownloadArchiveExtension: jest.SpyInstance; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); |
| 13 | + spyHttpClient.mockReturnValue({ |
| 14 | + statusCode: 200, |
| 15 | + headers: {}, |
| 16 | + result: manifestData |
| 17 | + }); |
| 18 | + |
| 19 | + spyUtilGetDownloadArchiveExtension = jest.spyOn( |
| 20 | + utils, |
| 21 | + 'getDownloadArchiveExtension' |
| 22 | + ); |
| 23 | + spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz'); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(() => { |
| 27 | + jest.resetAllMocks(); |
| 28 | + jest.clearAllMocks(); |
| 29 | + jest.restoreAllMocks(); |
| 30 | + }); |
| 31 | + |
| 32 | + const mockPlatform = ( |
| 33 | + distribution: DragonwellDistribution, |
| 34 | + platform: string |
| 35 | + ) => { |
| 36 | + distribution['getPlatformOption'] = () => platform; |
| 37 | + const mockedExtension = platform == 'windows' ? 'zip' : 'tar.gz'; |
| 38 | + spyUtilGetDownloadArchiveExtension.mockReturnValue(mockedExtension); |
| 39 | + }; |
| 40 | + |
| 41 | + describe('getAvailableVersions', () => { |
| 42 | + it.each([ |
| 43 | + ['8', 'x86', 'linux', 0], |
| 44 | + ['8', 'aarch64', 'linux', 24], |
| 45 | + ['8.6.6', 'x64', 'linux', 27], |
| 46 | + ['8', 'x86', 'anolis', 0], |
| 47 | + ['8', 'x86', 'windows', 0], |
| 48 | + ['8', 'x86', 'mac', 0], |
| 49 | + ['11', 'x64', 'linux', 27], |
| 50 | + ['11', 'aarch64', 'linux', 24], |
| 51 | + ['17', 'riscv', 'linux', 0], |
| 52 | + ['16.0.1', 'x64', 'linux', 27] |
| 53 | + ])( |
| 54 | + 'should get right number of available versions from JSON', |
| 55 | + async ( |
| 56 | + jdkVersion: string, |
| 57 | + arch: string, |
| 58 | + platform: string, |
| 59 | + len: number |
| 60 | + ) => { |
| 61 | + const distribution = new DragonwellDistribution({ |
| 62 | + version: jdkVersion, |
| 63 | + architecture: arch, |
| 64 | + packageType: 'jdk', |
| 65 | + checkLatest: false |
| 66 | + }); |
| 67 | + mockPlatform(distribution, platform); |
| 68 | + |
| 69 | + const availableVersions = await distribution['getAvailableVersions'](); |
| 70 | + expect(availableVersions).not.toBeNull(); |
| 71 | + expect(availableVersions.length).toBe(len); |
| 72 | + } |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('findPackageForDownload', () => { |
| 77 | + it.each([ |
| 78 | + [ |
| 79 | + '8', |
| 80 | + 'linux', |
| 81 | + 'x64', |
| 82 | + 'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_linux.tar.gz' |
| 83 | + ], |
| 84 | + [ |
| 85 | + '8', |
| 86 | + 'linux', |
| 87 | + 'aarch64', |
| 88 | + 'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_aarch64_linux.tar.gz' |
| 89 | + ], |
| 90 | + [ |
| 91 | + '8', |
| 92 | + 'windows', |
| 93 | + 'x64', |
| 94 | + 'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_windows.zip' |
| 95 | + ], |
| 96 | + [ |
| 97 | + '8.13.14', |
| 98 | + 'linux', |
| 99 | + 'x64', |
| 100 | + 'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_linux.tar.gz' |
| 101 | + ], |
| 102 | + [ |
| 103 | + '11', |
| 104 | + 'linux', |
| 105 | + 'x64', |
| 106 | + 'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_linux.tar.gz' |
| 107 | + ], |
| 108 | + [ |
| 109 | + '11', |
| 110 | + 'linux', |
| 111 | + 'aarch64', |
| 112 | + 'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_aarch64_linux.tar.gz' |
| 113 | + ], |
| 114 | + [ |
| 115 | + '11', |
| 116 | + 'windows', |
| 117 | + 'x64', |
| 118 | + 'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_windows.zip' |
| 119 | + ], |
| 120 | + [ |
| 121 | + '11', |
| 122 | + 'alpine-linux', |
| 123 | + 'x64', |
| 124 | + 'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_alpine-linux.tar.gz' |
| 125 | + ], |
| 126 | + [ |
| 127 | + '11.0.17', |
| 128 | + 'linux', |
| 129 | + 'x64', |
| 130 | + 'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_linux.tar.gz' |
| 131 | + ], |
| 132 | + [ |
| 133 | + '17', |
| 134 | + 'linux', |
| 135 | + 'x64', |
| 136 | + 'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_linux.tar.gz' |
| 137 | + ], |
| 138 | + [ |
| 139 | + '17', |
| 140 | + 'linux', |
| 141 | + 'aarch64', |
| 142 | + 'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_aarch64_linux.tar.gz' |
| 143 | + ], |
| 144 | + [ |
| 145 | + '17', |
| 146 | + 'windows', |
| 147 | + 'x64', |
| 148 | + 'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_windows.zip' |
| 149 | + ], |
| 150 | + [ |
| 151 | + '17', |
| 152 | + 'alpine-linux', |
| 153 | + 'x64', |
| 154 | + 'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_alpine-linux.tar.gz' |
| 155 | + ], |
| 156 | + [ |
| 157 | + '17.0.4', |
| 158 | + 'linux', |
| 159 | + 'x64', |
| 160 | + 'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.4.0.4%2B8_jdk-17.0.4-ga/Alibaba_Dragonwell_Standard_17.0.4.0.4%2B8_x64_linux.tar.gz' |
| 161 | + ] |
| 162 | + ])( |
| 163 | + 'should return proper link according to the specified java-version, platform and arch', |
| 164 | + async ( |
| 165 | + jdkVersion: string, |
| 166 | + platform: string, |
| 167 | + arch: string, |
| 168 | + expectedLink: string |
| 169 | + ) => { |
| 170 | + const distribution = new DragonwellDistribution({ |
| 171 | + version: jdkVersion, |
| 172 | + architecture: arch, |
| 173 | + packageType: 'jdk', |
| 174 | + checkLatest: false |
| 175 | + }); |
| 176 | + mockPlatform(distribution, platform); |
| 177 | + |
| 178 | + const availableVersion = await distribution['findPackageForDownload']( |
| 179 | + jdkVersion |
| 180 | + ); |
| 181 | + expect(availableVersion).not.toBeNull(); |
| 182 | + expect(availableVersion.url).toBe(expectedLink); |
| 183 | + } |
| 184 | + ); |
| 185 | + |
| 186 | + it.each([ |
| 187 | + ['8', 'alpine-linux', 'x64'], |
| 188 | + ['8', 'macos', 'aarch64'], |
| 189 | + ['11', 'macos', 'aarch64'], |
| 190 | + ['17', 'linux', 'riscv'] |
| 191 | + ])( |
| 192 | + 'should throw when required version of JDK can not be found in the JSON', |
| 193 | + async (jdkVersion: string, platform: string, arch: string) => { |
| 194 | + const distribution = new DragonwellDistribution({ |
| 195 | + version: jdkVersion, |
| 196 | + architecture: arch, |
| 197 | + packageType: 'jdk', |
| 198 | + checkLatest: false |
| 199 | + }); |
| 200 | + mockPlatform(distribution, platform); |
| 201 | + |
| 202 | + await expect( |
| 203 | + distribution['findPackageForDownload'](jdkVersion) |
| 204 | + ).rejects.toThrow( |
| 205 | + `Couldn't find any satisfied version for the specified java-version: "${jdkVersion}" and architecture: "${arch}".` |
| 206 | + ); |
| 207 | + } |
| 208 | + ); |
| 209 | + |
| 210 | + it('should throw when required package type is not jdk', async () => { |
| 211 | + const jdkVersion = '17'; |
| 212 | + const arch = 'x64'; |
| 213 | + const platform = 'linux'; |
| 214 | + const distribution = new DragonwellDistribution({ |
| 215 | + version: jdkVersion, |
| 216 | + architecture: arch, |
| 217 | + packageType: 'jre', |
| 218 | + checkLatest: false |
| 219 | + }); |
| 220 | + mockPlatform(distribution, platform); |
| 221 | + await expect( |
| 222 | + distribution['findPackageForDownload'](jdkVersion) |
| 223 | + ).rejects.toThrow('Dragonwell provides only the `jdk` package type'); |
| 224 | + }); |
| 225 | + }); |
| 226 | +}); |
0 commit comments