* refine the test execution

* fix according to comments
This commit is contained in:
Sheng Chen 2018-02-13 12:02:01 +08:00 коммит произвёл GitHub
Родитель bd7f9d6a59
Коммит d2b31ff776
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 50 добавлений и 27 удалений

Просмотреть файл

@ -11,9 +11,10 @@ import { TerminalType, TestOption, TFTerminal } from "./shared";
import { terraformChannel } from "./terraformChannel";
import { isServicePrincipalSetInEnv } from "./utils/azureUtils";
import { executeCommand } from "./utils/cpUtils";
import { isDockerInstalled, latestTestingImagePulled, runE2EInDocker, runLintInDocker } from "./utils/dockerUtils";
import { isDockerInstalled, runCustomCommandInDocker, runE2EInDocker, runLintInDocker } from "./utils/dockerUtils";
import { drawGraph } from "./utils/dotUtils";
import { isDotInstalled } from "./utils/dotUtils";
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
import { selectWorkspaceFolder } from "./utils/workspaceUtils";
export class IntegratedShell extends BaseShell {
@ -62,20 +63,16 @@ export class IntegratedShell extends BaseShell {
return;
}
terraformChannel.appendLine("Pulling the latest image of 'microsoft/terraform-test'...");
if (!await latestTestingImagePulled()) {
return;
}
let executeResult: boolean = false;
switch (TestType) {
case TestOption.lint:
await runLintInDocker(
executeResult = await runLintInDocker(
workingDirectory + ":/tf-test/module",
containerName,
);
break;
case TestOption.e2e:
await runE2EInDocker(
executeResult = await runE2EInDocker(
workingDirectory + ":/tf-test/module",
containerName,
);
@ -86,18 +83,17 @@ export class IntegratedShell extends BaseShell {
prompt: "Type your custom test command",
value: `run -v ${workingDirectory}:/tf-test/module --rm ${containerName} rake -f ../Rakefile build`,
});
if (cmd) {
await executeCommand(
"docker",
cmd.split(" "),
{ shell: true },
);
if (!cmd) {
return;
}
executeResult = await runCustomCommandInDocker(cmd, containerName);
break;
default:
console.log("Default step in test for Integrated Terminal");
break;
}
if (executeResult) {
await promptForOpenOutputChannel("The tests finished. Please open the output channel for more details.", DialogType.info);
}
}
public runTerraformCmd(tfCommand: string): void {

Просмотреть файл

@ -13,18 +13,11 @@ export async function isDockerInstalled(): Promise<boolean> {
}
}
export async function latestTestingImagePulled(): Promise<boolean> {
try {
await executeCommand("docker", ["pull", "microsoft/terraform-test:latest"], { shell: true });
return true;
} catch (error) {
promptForOpenOutputChannel("Failed to pull the latest image: microsoft/terraform-test. Please open the output channel for more details.", DialogType.error);
return false;
}
}
export async function runLintInDocker(volumn: string, containerName: string): Promise<void> {
export async function runLintInDocker(volumn: string, containerName: string): Promise<boolean> {
try {
if (!await pullLatestImage(containerName)) {
return false;
}
await executeCommand(
"docker",
[
@ -40,13 +33,18 @@ export async function runLintInDocker(volumn: string, containerName: string): Pr
],
{ shell: true },
);
return true;
} catch (error) {
promptForOpenOutputChannel("Failed to run lint task in Docker. Please open the output channel for more details.", DialogType.error);
return false;
}
}
export async function runE2EInDocker(volumn: string, containerName: string): Promise<void> {
export async function runE2EInDocker(volumn: string, containerName: string): Promise<boolean> {
try {
if (!await pullLatestImage(containerName)) {
return false;
}
await executeCommand(
"docker",
[
@ -73,7 +71,36 @@ export async function runE2EInDocker(volumn: string, containerName: string): Pro
],
{ shell: true },
);
return true;
} catch (error) {
promptForOpenOutputChannel("Failed to run end to end tests in Docker. Please open the output channel for more details.", DialogType.error);
return false;
}
}
export async function runCustomCommandInDocker(cmd: string, containerName: string): Promise<boolean> {
try {
if (!await pullLatestImage(containerName)) {
return false;
}
await executeCommand(
"docker",
cmd.split(" "),
{ shell: true },
);
return true;
} catch (error) {
promptForOpenOutputChannel("Failed to run the custom command in Docker. Please open the output channel for more details.", DialogType.error);
return false;
}
}
async function pullLatestImage(image: string): Promise<boolean> {
try {
await executeCommand("docker", ["pull", `${image}:latest`], { shell: true });
return true;
} catch (error) {
promptForOpenOutputChannel(`Failed to pull the latest image: ${image}. Please open the output channel for more details.`, DialogType.error);
return false;
}
}