|
| 1 | +import fs from 'fs'; |
| 2 | +import path from 'path'; |
| 3 | +import { |
| 4 | + JAVA_PLATFORM_CAPABILITIES, |
| 5 | + normalizeArchitecture, |
| 6 | + validateJavaPlatform |
| 7 | +} from '../src/distributions/platform-types.js'; |
| 8 | +import {JavaDistribution} from '../src/distributions/package-types.js'; |
| 9 | + |
| 10 | +describe('Java platform capabilities', () => { |
| 11 | + it('declares a capability for every distribution', () => { |
| 12 | + expect(Object.keys(JAVA_PLATFORM_CAPABILITIES).sort()).toEqual( |
| 13 | + Object.values(JavaDistribution).sort() |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + it.each([ |
| 18 | + ['x64', 'x64'], |
| 19 | + ['amd64', 'x64'], |
| 20 | + ['x86', 'x86'], |
| 21 | + ['ia32', 'x86'], |
| 22 | + ['arm', 'armv7'], |
| 23 | + ['aarch64', 'aarch64'], |
| 24 | + ['arm64', 'aarch64'], |
| 25 | + ['ppc64le', 'ppc64le'], |
| 26 | + ['s390x', 's390x'] |
| 27 | + ])('normalizes architecture %s to %s', (input, expected) => { |
| 28 | + expect(normalizeArchitecture(input)).toBe(expected); |
| 29 | + }); |
| 30 | + |
| 31 | + it('uses the normalized architecture for validation', () => { |
| 32 | + expect(validateJavaPlatform('microsoft', 'linux', 'arm64', '25')).toBe( |
| 33 | + 'aarch64' |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + it('rejects OS-specific restrictions with a consistent diagnostic', () => { |
| 38 | + expect(() => |
| 39 | + validateJavaPlatform('oracle', 'win32', 'arm64', '21') |
| 40 | + ).toThrow( |
| 41 | + "Distribution 'oracle' does not support operating system 'windows' with architecture 'aarch64' for Java version '21'. Supported combinations: linux (x64, aarch64); macos (x64, aarch64); windows (x64)." |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it('rejects version-dependent architecture restrictions', () => { |
| 46 | + expect(() => |
| 47 | + validateJavaPlatform('corretto', 'linux', 'x86', '17') |
| 48 | + ).toThrow(/x86 \(<12\)/); |
| 49 | + expect(() => |
| 50 | + validateJavaPlatform('corretto', 'linux', 'x86', '17.0.2.8.1') |
| 51 | + ).toThrow(/x86 \(<12\)/); |
| 52 | + expect(validateJavaPlatform('corretto', 'linux', 'x86', '11')).toBe('x86'); |
| 53 | + }); |
| 54 | + |
| 55 | + it.each(['corretto', 'kona'])( |
| 56 | + 'rejects Windows aarch64 for %s', |
| 57 | + distributionName => { |
| 58 | + expect(() => |
| 59 | + validateJavaPlatform(distributionName, 'win32', 'arm64', '21') |
| 60 | + ).toThrow(/does not support operating system 'windows'/); |
| 61 | + } |
| 62 | + ); |
| 63 | + |
| 64 | + it('keeps Adopt HotSpot aliases aligned with the Temurin-first resolver', () => { |
| 65 | + expect(validateJavaPlatform('adopt', 'darwin', 'arm64', '21')).toBe( |
| 66 | + 'aarch64' |
| 67 | + ); |
| 68 | + expect(validateJavaPlatform('adopt-hotspot', 'win32', 'arm64', '21')).toBe( |
| 69 | + 'aarch64' |
| 70 | + ); |
| 71 | + expect(() => |
| 72 | + validateJavaPlatform('adopt-openj9', 'darwin', 'arm64', '16') |
| 73 | + ).toThrow(/does not support operating system 'macos'/); |
| 74 | + }); |
| 75 | + |
| 76 | + it('allows local archives on any platform and architecture', () => { |
| 77 | + expect(validateJavaPlatform('jdkfile', 'aix', 'mips64', '21')).toBe( |
| 78 | + 'mips64' |
| 79 | + ); |
| 80 | + }); |
| 81 | + |
| 82 | + it('keeps the documented architecture contract aligned', () => { |
| 83 | + const repositoryRoot = process.cwd(); |
| 84 | + const readRepositoryFile = (filePath: string) => |
| 85 | + fs.readFileSync(path.join(repositoryRoot, filePath), 'utf8'); |
| 86 | + |
| 87 | + for (const filePath of ['action.yml', 'README.md']) { |
| 88 | + const content = readRepositoryFile(filePath); |
| 89 | + for (const architecture of [ |
| 90 | + 'x86', |
| 91 | + 'x64', |
| 92 | + 'armv7', |
| 93 | + 'aarch64', |
| 94 | + 'ppc64le', |
| 95 | + 'ppc64', |
| 96 | + 's390x' |
| 97 | + ]) { |
| 98 | + expect(content).toContain(architecture); |
| 99 | + } |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + it.each(Object.entries(JAVA_PLATFORM_CAPABILITIES))( |
| 104 | + 'keeps the advanced compatibility table aligned for %s', |
| 105 | + (distributionName, capability) => { |
| 106 | + const advancedUsage = fs.readFileSync( |
| 107 | + path.join(process.cwd(), 'docs/advanced-usage.md'), |
| 108 | + 'utf8' |
| 109 | + ); |
| 110 | + const compatibilityTable = advancedUsage.slice( |
| 111 | + advancedUsage.indexOf('## Platform and architecture compatibility') |
| 112 | + ); |
| 113 | + const compatibilityRow = compatibilityTable |
| 114 | + .split('\n') |
| 115 | + .find( |
| 116 | + line => |
| 117 | + line.startsWith('|') && line.includes(`\`${distributionName}\``) |
| 118 | + ); |
| 119 | + |
| 120 | + expect(compatibilityRow).toBeDefined(); |
| 121 | + if (!('platforms' in capability)) { |
| 122 | + expect(compatibilityRow).toContain('Any'); |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + const architectures = new Set( |
| 127 | + Object.values(capability.platforms) |
| 128 | + .flat() |
| 129 | + .map(item => (typeof item === 'string' ? item : item.architecture)) |
| 130 | + ); |
| 131 | + for (const architecture of architectures) { |
| 132 | + expect(compatibilityRow).toContain(`\`${architecture}\``); |
| 133 | + } |
| 134 | + } |
| 135 | + ); |
| 136 | +}); |
0 commit comments