|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { |
| 3 | + aptTargetLabels, |
| 4 | + aptTargetPgVersions, |
| 5 | + buildAptInstallCommand, |
| 6 | + buildRpmInstallCommand, |
| 7 | + rpmTargetLabels, |
| 8 | +} from '../app/lib/packageInstall'; |
| 9 | +import type { |
| 10 | + AptArch, |
| 11 | + AptDistro, |
| 12 | + RpmArch, |
| 13 | + RpmDistro, |
| 14 | + RpmPgVersion, |
| 15 | +} from '../app/lib/packageInstall'; |
| 16 | + |
| 17 | +/** |
| 18 | + * These commands are published on /packages for users to copy and paste, so a |
| 19 | + * wrong codename or architecture is a broken install instruction on a public |
| 20 | + * site rather than a failing test somewhere internal. The maps below are |
| 21 | + * duplicated from the implementation on purpose: an accidental edit to the |
| 22 | + * private mapping should have to be made deliberately in two places. |
| 23 | + */ |
| 24 | +const expectedPgdgSuites: Record<AptDistro, string> = { |
| 25 | + ubuntu22: 'jammy', |
| 26 | + ubuntu24: 'noble', |
| 27 | + deb11: 'bullseye', |
| 28 | + deb12: 'bookworm', |
| 29 | + deb13: 'trixie', |
| 30 | +}; |
| 31 | + |
| 32 | +const expectedRhelMajors: Record<RpmDistro, string> = { |
| 33 | + rhel8: '8', |
| 34 | + rhel9: '9', |
| 35 | +}; |
| 36 | + |
| 37 | +const aptDistros = Object.keys(aptTargetLabels) as AptDistro[]; |
| 38 | +const rpmDistros = Object.keys(rpmTargetLabels) as RpmDistro[]; |
| 39 | +const aptArches: AptArch[] = ['amd64', 'arm64']; |
| 40 | +const rpmArches: RpmArch[] = ['x86_64', 'aarch64']; |
| 41 | +const rpmPgVersions: RpmPgVersion[] = ['16', '17', '18']; |
| 42 | + |
| 43 | +/** Every APT distro/arch/version combination the packages page can offer. */ |
| 44 | +const aptMatrix = aptDistros.flatMap((distro) => |
| 45 | + aptArches.flatMap((arch) => |
| 46 | + aptTargetPgVersions[distro].map((pg) => ({ distro, arch, pg })), |
| 47 | + ), |
| 48 | +); |
| 49 | + |
| 50 | +const rpmMatrix = rpmDistros.flatMap((distro) => |
| 51 | + rpmArches.flatMap((arch) => rpmPgVersions.map((pg) => ({ distro, arch, pg }))), |
| 52 | +); |
| 53 | + |
| 54 | +describe('package metadata', () => { |
| 55 | + it('declares supported PostgreSQL versions for every labelled APT target', () => { |
| 56 | + for (const distro of aptDistros) { |
| 57 | + expect(aptTargetPgVersions[distro], `no versions declared for ${distro}`).toBeDefined(); |
| 58 | + expect(aptTargetPgVersions[distro].length).toBeGreaterThan(0); |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + it('covers every labelled APT target in the PGDG suite mapping', () => { |
| 63 | + // A target added to the labels without a matching suite would silently |
| 64 | + // produce "deb ... undefined-pgdg main" in a published command. |
| 65 | + expect(Object.keys(expectedPgdgSuites).sort()).toEqual([...aptDistros].sort()); |
| 66 | + }); |
| 67 | +}); |
| 68 | + |
| 69 | +describe('buildAptInstallCommand', () => { |
| 70 | + it.each(aptMatrix)('produces a complete command for $distro/$arch/pg$pg', ({ distro, arch, pg }) => { |
| 71 | + const command = buildAptInstallCommand(distro, arch, pg); |
| 72 | + // Deliberately not matching "null": these commands legitimately redirect |
| 73 | + // to /dev/null. |
| 74 | + expect(command).not.toMatch(/undefined|NaN/); |
| 75 | + }); |
| 76 | + |
| 77 | + it.each(aptDistros)('uses the correct PGDG suite for %s', (distro) => { |
| 78 | + const command = buildAptInstallCommand(distro, 'amd64', aptTargetPgVersions[distro][0]); |
| 79 | + expect(command).toContain(`/pub/repos/apt ${expectedPgdgSuites[distro]}-pgdg main`); |
| 80 | + }); |
| 81 | + |
| 82 | + it.each(aptArches)('pins the DocumentDB repository to arch %s', (arch) => { |
| 83 | + const command = buildAptInstallCommand('ubuntu24', arch, '16'); |
| 84 | + expect(command).toContain(`[arch=${arch} `); |
| 85 | + }); |
| 86 | + |
| 87 | + it.each(aptDistros)('uses %s as the DocumentDB repository component', (distro) => { |
| 88 | + const command = buildAptInstallCommand(distro, 'amd64', aptTargetPgVersions[distro][0]); |
| 89 | + expect(command).toContain(`documentdb.io/deb stable ${distro}`); |
| 90 | + }); |
| 91 | + |
| 92 | + it.each(aptMatrix)('installs postgresql-$pg-documentdb for $distro/$arch', ({ distro, arch, pg }) => { |
| 93 | + const command = buildAptInstallCommand(distro, arch, pg); |
| 94 | + expect(command).toContain(`sudo apt install -y postgresql-${pg}-documentdb`); |
| 95 | + }); |
| 96 | + |
| 97 | + it('does not offer PostgreSQL 18 on Debian 11', () => { |
| 98 | + // Documented on the packages page: PGDG bullseye resolves 16 and 17 only. |
| 99 | + expect(aptTargetPgVersions.deb11).not.toContain('18'); |
| 100 | + }); |
| 101 | +}); |
| 102 | + |
| 103 | +describe('buildRpmInstallCommand', () => { |
| 104 | + it.each(rpmMatrix)('produces a complete command for $distro/$arch/pg$pg', ({ distro, arch, pg }) => { |
| 105 | + const command = buildRpmInstallCommand(distro, arch, pg); |
| 106 | + // Deliberately not matching "null": these commands legitimately redirect |
| 107 | + // to /dev/null. |
| 108 | + expect(command).not.toMatch(/undefined|NaN/); |
| 109 | + }); |
| 110 | + |
| 111 | + it.each(rpmDistros)('derives the EL major version for %s', (distro) => { |
| 112 | + const major = expectedRhelMajors[distro]; |
| 113 | + const command = buildRpmInstallCommand(distro, 'x86_64', '16'); |
| 114 | + expect(command).toContain(`epel-release-latest-${major}.noarch.rpm`); |
| 115 | + expect(command).toContain(`EL-${major}-x86_64`); |
| 116 | + }); |
| 117 | + |
| 118 | + it.each(rpmArches)('uses arch %s in the PGDG and CodeReady repository names', (arch) => { |
| 119 | + const command = buildRpmInstallCommand('rhel9', arch, '16'); |
| 120 | + expect(command).toContain(`EL-9-${arch}/pgdg-redhat-repo-latest.noarch.rpm`); |
| 121 | + expect(command).toContain(`codeready-builder-for-rhel-9-${arch}-rpms`); |
| 122 | + }); |
| 123 | + |
| 124 | + it.each(rpmDistros)('points the DocumentDB repository at rpm/%s', (distro) => { |
| 125 | + const command = buildRpmInstallCommand(distro, 'x86_64', '16'); |
| 126 | + expect(command).toContain(`baseurl=https://documentdb.io/rpm/${distro}`); |
| 127 | + }); |
| 128 | + |
| 129 | + it.each(rpmMatrix)('installs postgresql$pg-documentdb for $distro/$arch', ({ distro, arch, pg }) => { |
| 130 | + const command = buildRpmInstallCommand(distro, arch, pg); |
| 131 | + expect(command).toContain(`sudo dnf install -y postgresql${pg}-documentdb`); |
| 132 | + }); |
| 133 | + |
| 134 | + it('enables gpgcheck against the DocumentDB signing key', () => { |
| 135 | + const command = buildRpmInstallCommand('rhel9', 'x86_64', '16'); |
| 136 | + expect(command).toContain("'gpgcheck=1'"); |
| 137 | + expect(command).toContain("'gpgkey=https://documentdb.io/documentdb-archive-keyring.gpg'"); |
| 138 | + }); |
| 139 | +}); |
0 commit comments