run terraform tests in integrated terminal
This commit is contained in:
Родитель
5637a271cd
Коммит
6e52c93a7c
|
@ -14,14 +14,11 @@ import { TelemetryWrapper } from "vscode-extension-telemetry-wrapper";
|
|||
import { BaseShell } from "./baseShell";
|
||||
import { Constants } from "./constants";
|
||||
import { TestOption } from "./shared";
|
||||
import { terraformChannel } from "./terraformChannel";
|
||||
import { isServicePrincipalSetInEnv } from "./utils/azureUtils";
|
||||
import { executeCommand } from "./utils/cpUtils";
|
||||
import { isDockerInstalled, runCustomCommandInDocker, runE2EInDocker, runLintInDocker } from "./utils/dockerUtils";
|
||||
import { drawGraph } from "./utils/dotUtils";
|
||||
import { isDotInstalled } from "./utils/dotUtils";
|
||||
import * as settingUtils from "./utils/settingUtils";
|
||||
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
|
||||
import { selectWorkspaceFolder } from "./utils/workspaceUtils";
|
||||
|
||||
export class IntegratedShell extends BaseShell {
|
||||
|
@ -68,22 +65,15 @@ export class IntegratedShell extends BaseShell {
|
|||
}
|
||||
const containerName: string = settingUtils.getImageNameForTest();
|
||||
|
||||
terraformChannel.appendLine("Checking Azure Service Principal environment variables...");
|
||||
if (!isServicePrincipalSetInEnv()) {
|
||||
TelemetryWrapper.error("servicePrincipalEnvInvalid");
|
||||
return;
|
||||
}
|
||||
|
||||
let executeResult: boolean = false;
|
||||
switch (TestType) {
|
||||
case TestOption.lint:
|
||||
executeResult = await runLintInDocker(
|
||||
await runLintInDocker(
|
||||
workingDirectory + ":/tf-test/module",
|
||||
containerName,
|
||||
);
|
||||
break;
|
||||
case TestOption.e2e:
|
||||
executeResult = await runE2EInDocker(
|
||||
await runE2EInDocker(
|
||||
workingDirectory + ":/tf-test/module",
|
||||
containerName,
|
||||
);
|
||||
|
@ -97,14 +87,11 @@ export class IntegratedShell extends BaseShell {
|
|||
if (!cmd) {
|
||||
return;
|
||||
}
|
||||
executeResult = await runCustomCommandInDocker(cmd, containerName);
|
||||
await runCustomCommandInDocker(cmd, containerName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (executeResult) {
|
||||
await promptForOpenOutputChannel("The tests finished. Please open the output channel for more details.", DialogType.info);
|
||||
}
|
||||
}
|
||||
|
||||
public runTerraformCmd(tfCommand: string): void {
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import { openUrlHint } from "./uiUtils";
|
||||
|
||||
export function isServicePrincipalSetInEnv(): boolean {
|
||||
if (!(process.env.ARM_SUBSCRIPTION_ID && process.env.ARM_CLIENT_ID && process.env.ARM_CLIENT_SECRET &&
|
||||
process.env.ARM_TENANT_ID && process.env.ARM_TEST_LOCATION)) {
|
||||
openUrlHint(
|
||||
"Azure Service Principal is not set.",
|
||||
"https://www.terraform.io/docs/providers/azurerm/authenticating_via_service_principal.html",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
"use strict";
|
||||
|
||||
import { executeCommand } from "./cpUtils";
|
||||
import { terraformShellManager } from "../terraformShellManager";
|
||||
import { DialogType, openUrlHint, promptForOpenOutputChannel } from "./uiUtils";
|
||||
|
||||
export async function isDockerInstalled(): Promise<boolean> {
|
||||
|
@ -23,21 +24,8 @@ export async function runLintInDocker(volumn: string, containerName: string): Pr
|
|||
if (!await pullLatestImage(containerName)) {
|
||||
return false;
|
||||
}
|
||||
await executeCommand(
|
||||
"docker",
|
||||
[
|
||||
"run",
|
||||
"-v",
|
||||
volumn,
|
||||
"--rm",
|
||||
containerName,
|
||||
"rake",
|
||||
"-f",
|
||||
"../Rakefile",
|
||||
"build",
|
||||
],
|
||||
{ shell: true },
|
||||
);
|
||||
const cmd: string = `docker run -v ${volumn} --rm ${containerName} rake -f ../Rakefile build`
|
||||
terraformShellManager.getIntegratedShell().runTerraformCmd(cmd)
|
||||
return true;
|
||||
} catch (error) {
|
||||
promptForOpenOutputChannel("Failed to run lint task in Docker. Please open the output channel for more details.", DialogType.error);
|
||||
|
@ -50,32 +38,16 @@ export async function runE2EInDocker(volumn: string, containerName: string): Pro
|
|||
if (!await pullLatestImage(containerName)) {
|
||||
return false;
|
||||
}
|
||||
await executeCommand(
|
||||
"docker",
|
||||
[
|
||||
"run",
|
||||
"-v",
|
||||
volumn,
|
||||
"-e",
|
||||
"ARM_CLIENT_ID",
|
||||
"-e",
|
||||
"ARM_TENANT_ID",
|
||||
"-e",
|
||||
"ARM_SUBSCRIPTION_ID",
|
||||
"-e",
|
||||
"ARM_CLIENT_SECRET",
|
||||
"-e",
|
||||
"ARM_TEST_LOCATION",
|
||||
"-e",
|
||||
"ARM_TEST_LOCATION_ALT",
|
||||
"--rm",
|
||||
containerName,
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
`"ssh-keygen -t rsa -b 2048 -C terraformTest -f /root/.ssh/id_rsa -N ''; rake -f ../Rakefile e2e"`,
|
||||
],
|
||||
{ shell: true },
|
||||
);
|
||||
const cmd: string = `docker run -v ${volumn} `
|
||||
+ `-e ARM_CLIENT_ID `
|
||||
+ `-e ARM_TENANT_ID `
|
||||
+ `-e ARM_SUBSCRIPTION_ID `
|
||||
+ `-e ARM_CLIENT_SECRET `
|
||||
+ `-e ARM_TEST_LOCATION `
|
||||
+ `-e ARM_TEST_LOCATION_ALT `
|
||||
+ `--rm ${containerName} /bin/bash -c `
|
||||
+ `"ssh-keygen -t rsa -b 2048 -C terraformTest -f /root/.ssh/id_rsa -N ''; rake -f ../Rakefile e2e"`
|
||||
terraformShellManager.getIntegratedShell().runTerraformCmd(cmd)
|
||||
return true;
|
||||
} catch (error) {
|
||||
promptForOpenOutputChannel("Failed to run end to end tests in Docker. Please open the output channel for more details.", DialogType.error);
|
||||
|
|
Загрузка…
Ссылка в новой задаче