Skip to content

Commit 1de0c4c

Browse files
authored
Add autoUpdatable flag and refactor installer logic (#6623)
Add autoUpdatable flag and refactor installer logic
1 parent 84ffd4d commit 1de0c4c

File tree

2 files changed

+59
-34
lines changed

2 files changed

+59
-34
lines changed

packages/compass-e2e-tests/helpers/smoke-test/build-info.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export function assertBuildInfoIsRHEL(
9292
export type PackageDetails = {
9393
kind: PackageKind;
9494
filename: string;
95+
autoUpdatable: boolean;
9596
} & (
9697
| {
9798
kind: 'windows_setup' | 'windows_msi' | 'windows_zip';
@@ -124,16 +125,36 @@ export function getPackageDetails(
124125
kind === 'windows_zip'
125126
) {
126127
assertBuildInfoIsWindows(buildInfo);
127-
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
128+
return {
129+
kind,
130+
buildInfo,
131+
filename: buildInfo[`${kind}_filename`],
132+
autoUpdatable: kind === 'windows_setup',
133+
};
128134
} else if (kind === 'osx_dmg' || kind === 'osx_zip') {
129135
assertBuildInfoIsOSX(buildInfo);
130-
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
136+
return {
137+
kind,
138+
buildInfo,
139+
filename: buildInfo[`${kind}_filename`],
140+
autoUpdatable: true,
141+
};
131142
} else if (kind === 'linux_deb' || kind === 'linux_tar') {
132143
assertBuildInfoIsUbuntu(buildInfo);
133-
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
144+
return {
145+
kind,
146+
buildInfo,
147+
filename: buildInfo[`${kind}_filename`],
148+
autoUpdatable: false,
149+
};
134150
} else if (kind === 'linux_rpm' || kind === 'rhel_tar') {
135151
assertBuildInfoIsRHEL(buildInfo);
136-
return { kind, buildInfo, filename: buildInfo[`${kind}_filename`] };
152+
return {
153+
kind,
154+
buildInfo,
155+
filename: buildInfo[`${kind}_filename`],
156+
autoUpdatable: false,
157+
};
137158
} else {
138159
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
139160
throw new Error(`Unsupported package kind: ${kind}`);

packages/compass-e2e-tests/smoke-test.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
} from './helpers/smoke-test/build-info';
1616
import { createSandbox } from './helpers/smoke-test/directories';
1717
import { downloadFile } from './helpers/smoke-test/downloads';
18-
import { SUPPORTED_PACKAGES } from './helpers/smoke-test/packages';
18+
import {
19+
type PackageKind,
20+
SUPPORTED_PACKAGES,
21+
} from './helpers/smoke-test/packages';
1922
import { type SmokeTestsContext } from './helpers/smoke-test/context';
2023
import { installMacZIP } from './installers/mac-zip';
2124

@@ -98,7 +101,14 @@ const argv = yargs(hideBin(process.argv))
98101
description: 'Use the local package instead of downloading',
99102
});
100103

101-
type TestSubject = PackageDetails & { filepath: string };
104+
type TestSubject = PackageDetails & {
105+
filepath: string;
106+
/**
107+
* Is the package unsigned?
108+
* In which case we'll expect auto-updating to fail.
109+
*/
110+
unsigned?: boolean;
111+
};
102112

103113
/**
104114
* Either finds the local package or downloads the package
@@ -120,6 +130,7 @@ async function getTestSubject(
120130
return {
121131
...details,
122132
filepath: path.resolve(compassDistPath, details.filename),
133+
unsigned: true,
123134
};
124135
} else {
125136
assert(
@@ -137,6 +148,16 @@ async function getTestSubject(
137148
}
138149
}
139150

151+
function getInstaller(kind: PackageKind) {
152+
if (kind === 'osx_dmg') {
153+
return installMacDMG;
154+
} else if (kind === 'osx_zip') {
155+
return installMacZIP;
156+
} else {
157+
throw new Error(`Installer for '${kind}' is not yet implemented`);
158+
}
159+
}
160+
140161
async function run() {
141162
const context: SmokeTestsContext = {
142163
...argv.parseSync(),
@@ -157,43 +178,26 @@ async function run() {
157178
])
158179
);
159180

160-
const cleanups: (() => void | Promise<void>)[] = [
161-
() => {
162-
console.log('Cleaning up sandbox');
163-
fs.rmSync(context.sandboxPath, { recursive: true });
164-
},
165-
];
166181
const { kind, buildInfo, filepath } = await getTestSubject(context);
182+
const install = getInstaller(kind);
167183

168184
try {
169185
const appName = buildInfo.productName;
170-
if (kind === 'osx_dmg') {
171-
const { appPath, uninstall } = installMacDMG({
172-
appName,
173-
filepath,
174-
destinationPath: context.sandboxPath,
175-
});
176-
cleanups.push(uninstall);
177186

178-
runTest({ appName, appPath });
179-
} else if (kind === 'osx_zip') {
180-
const { appPath, uninstall } = installMacZIP({
181-
appName,
182-
filepath,
183-
destinationPath: context.sandboxPath,
184-
});
185-
cleanups.push(uninstall);
187+
const { appPath, uninstall } = install({
188+
appName,
189+
filepath,
190+
destinationPath: context.sandboxPath,
191+
});
186192

193+
try {
187194
runTest({ appName, appPath });
188-
} else {
189-
throw new Error(`Testing '${kind}' packages is not yet implemented`);
195+
} finally {
196+
await uninstall();
190197
}
191198
} finally {
192-
// Chain the cleanup functions in reverse order
193-
await cleanups
194-
.slice()
195-
.reverse()
196-
.reduce((previous, cleanup) => previous.then(cleanup), Promise.resolve());
199+
console.log('Cleaning up sandbox');
200+
fs.rmSync(context.sandboxPath, { recursive: true });
197201
}
198202
}
199203

0 commit comments

Comments
 (0)