test: add regression scenario coverage
This commit is contained in:
@@ -15,13 +15,36 @@ const delayFor = async (millisecondsArg: number) => {
|
||||
await new Promise((resolveArg) => setTimeout(resolveArg, millisecondsArg));
|
||||
};
|
||||
|
||||
const outputCommand = async (
|
||||
commandArg: string,
|
||||
argsArg: string[],
|
||||
optionsArg: Pick<Deno.CommandOptions, 'stdout' | 'stderr'>,
|
||||
timeoutMsArg = 30000,
|
||||
) => {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMsArg);
|
||||
try {
|
||||
const command = new Deno.Command(commandArg, {
|
||||
args: argsArg,
|
||||
signal: controller.signal,
|
||||
...optionsArg,
|
||||
});
|
||||
return await command.output();
|
||||
} catch (error) {
|
||||
if ((error as Error).name === 'AbortError') {
|
||||
throw new Error(`${commandArg} ${argsArg.join(' ')} timed out after ${timeoutMsArg}ms`);
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
|
||||
const run = async (commandArg: string, argsArg: string[]) => {
|
||||
const command = new Deno.Command(commandArg, {
|
||||
args: argsArg,
|
||||
const output = await outputCommand(commandArg, argsArg, {
|
||||
stdout: 'piped',
|
||||
stderr: 'piped',
|
||||
});
|
||||
const output = await command.output();
|
||||
const stdout = new TextDecoder().decode(output.stdout).trim();
|
||||
const stderr = new TextDecoder().decode(output.stderr).trim();
|
||||
if (stdout) {
|
||||
@@ -48,12 +71,11 @@ const waitFor = async (checkFunctionArg: () => boolean | Promise<boolean>, messa
|
||||
};
|
||||
|
||||
const dockerServiceExists = async (serviceNameArg: string) => {
|
||||
const command = new Deno.Command('docker', {
|
||||
args: ['service', 'inspect', serviceNameArg],
|
||||
const output = await outputCommand('docker', ['service', 'inspect', serviceNameArg], {
|
||||
stdout: 'null',
|
||||
stderr: 'null',
|
||||
});
|
||||
return (await command.output()).success;
|
||||
}, 15000);
|
||||
return output.success;
|
||||
};
|
||||
|
||||
const removeDockerService = async (serviceNameArg: string) => {
|
||||
@@ -71,12 +93,16 @@ const assertNoPreexistingOneboxIngress = async () => {
|
||||
|
||||
const waitForDockerServiceRunning = async (serviceNameArg: string) => {
|
||||
await waitFor(async () => {
|
||||
const command = new Deno.Command('docker', {
|
||||
args: ['service', 'ps', serviceNameArg, '--format', '{{.CurrentState}}'],
|
||||
const output = await outputCommand('docker', [
|
||||
'service',
|
||||
'ps',
|
||||
serviceNameArg,
|
||||
'--format',
|
||||
'{{.CurrentState}}',
|
||||
], {
|
||||
stdout: 'piped',
|
||||
stderr: 'null',
|
||||
});
|
||||
const output = await command.output();
|
||||
}, 15000);
|
||||
if (!output.success) {
|
||||
return false;
|
||||
}
|
||||
@@ -205,4 +231,10 @@ const main = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
await main();
|
||||
try {
|
||||
await main();
|
||||
Deno.exit(0);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user