Skip to content

Commit

Permalink
feat(MongoBinaryDownloadUrl::getUbuntuVersionString): handle falling …
Browse files Browse the repository at this point in the history
…back to default version better
  • Loading branch information
hasezoey committed May 8, 2023
1 parent 5f3e5c8 commit 8bf3d88
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/guides/supported-systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Depends on the distribution, many common ones should just work right out of the
(uses mongodb's `ubuntu` release)<br/>
Lowest supported Distribution version is `1404`<br/>
Highest version is `2204`<br/>
Default version is `1404`<br/>
Default version is `2204`<br/>
Architectures Supported: `x86_64`, `arm64`(`aarch64`)

:::note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export interface MongoBinaryDownloadUrlOpts {
os?: AnyOS;
}

/** Set the default ubuntu version number */
export const DEFAULT_UBUNTU_YEAR = 22; // TODO: try to keep this up-to-date to the latest LTS

/**
* Download URL generator
*/
Expand Down Expand Up @@ -463,14 +466,19 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
ubuntuOS = {
os: 'linux',
dist: 'ubuntu',
release: '20.04', // TODO: try to keep this up-to-date to the latest LTS
release: `${DEFAULT_UBUNTU_YEAR}.04`,
};
} else {
ubuntuOS = os;
}
}

const ubuntuYear: number = parseInt(ubuntuOS.release.split('.')[0], 10);
let ubuntuYear: number = parseInt(ubuntuOS.release.split('.')[0], 10);

if (Number.isNaN(ubuntuYear)) {
console.warn(`Could not parse ubuntu year from "${ubuntuOS.release}", using default`);
ubuntuYear = DEFAULT_UBUNTU_YEAR;
}

if (this.arch === 'aarch64') {
// this is because, before version 4.1.10, everything for "arm64" / "aarch64" were just "arm64" and for "ubuntu1604"
Expand Down Expand Up @@ -514,9 +522,8 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
return 'ubuntu2004';
}

// TODO: change or remove "14" default, since it no-longer is supported above 4.0
// the "04" version always exists for ubuntu, use that as default
return `ubuntu${ubuntuYear || 14}04`;
return `ubuntu${ubuntuYear}04`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,15 +1608,30 @@ describe('MongoBinaryDownloadUrl', () => {
// Test for https://github.com/nodkz/mongodb-memory-server/issues/616
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => void 0);

downloadUrl.version = '5.0.3';
downloadUrl.version = '6.0.4';
expect(
downloadUrl.getUbuntuVersionString({
os: 'linux',
dist: 'zorin',
release: '16',
id_like: ['ubuntu'],
})
).toBe('ubuntu2004');
).toBe('ubuntu2204');

expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
});

it('should fallback to default version if release is not parsed correctly', () => {
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => void 0);

downloadUrl.version = '6.0.4';
expect(
downloadUrl.getUbuntuVersionString({
os: 'linux',
dist: 'Ubuntu Linux',
release: 'nan',
})
).toBe('ubuntu2204');

expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
});
Expand Down

0 comments on commit 8bf3d88

Please sign in to comment.