Skip to content

Commit ce72c8b

Browse files
committed
download and test with the latest release
1 parent 0f73014 commit ce72c8b

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

packages/compass-smoke-tests/src/build-info.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { type PackageKind } from './packages';
88
import { type SmokeTestsContext } from './context';
99
import { pick } from 'lodash';
1010

11+
const SUPPORTED_CHANNELS = ['dev', 'beta', 'stable'] as const;
12+
1113
function assertObjectHasKeys(
1214
obj: unknown,
1315
name: string,
@@ -25,13 +27,21 @@ function assertObjectHasKeys(
2527

2628
// subsets of the hadron-build info result
2729

28-
export const commonKeys = ['productName'] as const;
29-
export type CommonBuildInfo = Record<typeof commonKeys[number], string>;
30+
export const commonKeys = ['productName', 'channel'] as const;
31+
export type CommonBuildInfo = Record<typeof commonKeys[number], string> & {
32+
channel: 'dev' | 'beta' | 'stable';
33+
};
3034

3135
export function assertCommonBuildInfo(
3236
buildInfo: unknown
3337
): asserts buildInfo is CommonBuildInfo {
3438
assertObjectHasKeys(buildInfo, 'buildInfo', commonKeys);
39+
assert(
40+
SUPPORTED_CHANNELS.includes((buildInfo as any).channel),
41+
`Expected ${(buildInfo as any).channel} to be in ${SUPPORTED_CHANNELS.join(
42+
','
43+
)}`
44+
);
3545
}
3646

3747
export const windowsFilenameKeys = [

packages/compass-smoke-tests/src/cli.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,60 @@ async function getTestSubject(
145145
}
146146
}
147147

148+
type Arch = 'arm64' | 'x64';
149+
150+
type PlatformShortName =
151+
| 'darwin-arm64'
152+
| 'darwin-x64'
153+
| 'windows'
154+
| 'linux_deb'
155+
| 'linux_rpm';
156+
157+
function getPlatformShortName(
158+
arch: Arch,
159+
kind: PackageKind
160+
): PlatformShortName {
161+
if (arch === 'arm64') {
162+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
163+
return 'darwin-arm64';
164+
}
165+
}
166+
if (arch === 'x64') {
167+
if (kind === 'osx_dmg' || kind === 'osx_zip') {
168+
return 'darwin-x64';
169+
}
170+
if (
171+
kind === 'windows_setup' ||
172+
kind === 'windows_msi' ||
173+
kind === 'windows_zip'
174+
) {
175+
return 'windows';
176+
}
177+
if (kind === 'linux_deb' || kind === 'linux_tar') {
178+
return 'linux_deb';
179+
}
180+
if (kind === 'linux_rpm' || kind === 'rhel_tar') {
181+
return 'linux_rpm';
182+
}
183+
}
184+
185+
throw new Error(`Unsupported arch/kind combo: ${arch}/${kind}`);
186+
}
187+
188+
async function getLatestRelease(
189+
channel: 'dev' | 'beta' | 'stable',
190+
arch: Arch,
191+
kind: PackageKind,
192+
forceDownload?: boolean
193+
): Promise<string> {
194+
const shortName = getPlatformShortName(arch, kind);
195+
196+
return await downloadFile({
197+
url: `http://compass.mongodb.com/api/v2/download/latest/compass/${channel}/${shortName}`,
198+
clearCache: forceDownload,
199+
});
200+
}
201+
148202
function getInstaller(kind: PackageKind) {
149203
if (kind === 'osx_dmg') {
150204
return installMacDMG;
@@ -179,6 +233,8 @@ async function run() {
179233
const install = getInstaller(kind);
180234

181235
try {
236+
console.log('downgrade from this package to latest release');
237+
182238
const appName = buildInfo.productName;
183239

184240
const { appPath, uninstall } = install({
@@ -196,6 +252,33 @@ async function run() {
196252
console.log('Cleaning up sandbox');
197253
fs.rmSync(context.sandboxPath, { recursive: true });
198254
}
255+
256+
console.log('update from latest release to this package');
257+
const releasepath = await getLatestRelease(
258+
buildInfo.channel,
259+
context.arch,
260+
kind,
261+
context.forceDownload
262+
);
263+
264+
try {
265+
const appName = buildInfo.productName;
266+
267+
const { appPath, uninstall } = install({
268+
appName,
269+
filepath: releasepath,
270+
destinationPath: context.sandboxPath,
271+
});
272+
273+
try {
274+
runTest({ appName, appPath });
275+
} finally {
276+
await uninstall();
277+
}
278+
} finally {
279+
console.log('Cleaning up sandbox');
280+
fs.rmSync(context.sandboxPath, { recursive: true });
281+
}
199282
}
200283

201284
type RunTestOptions = {

packages/compass-smoke-tests/src/downloads.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ensureDownloadsDirectory } from './directories';
77

88
type DownloadFileOptions = {
99
url: string;
10-
targetFilename: string;
10+
targetFilename?: string;
1111
clearCache?: boolean;
1212
};
1313

@@ -18,6 +18,14 @@ export async function downloadFile({
1818
}: DownloadFileOptions): Promise<string> {
1919
const response = await fetch(url);
2020

21+
if (!targetFilename) {
22+
// if no filename was specified, work out the filename based on the final
23+
// URL the way a browser would
24+
targetFilename = path.basename(new URL(response.url).pathname);
25+
}
26+
27+
assert(targetFilename, 'Expected a filename');
28+
2129
const etag = response.headers.get('etag');
2230
assert(etag, 'Expected an ETag header');
2331
const cleanEtag = etag.match(/[0-9a-fA-F]/g)?.join('');
@@ -50,5 +58,7 @@ export async function downloadFile({
5058
fs.createWriteStream(outputPath)
5159
);
5260

61+
console.log(outputPath);
62+
5363
return outputPath;
5464
}

0 commit comments

Comments
 (0)