* Deploy static website project

* Update code according to comments

* Add website verification function

* Update code according to comments
This commit is contained in:
v-wuzhai 2021-04-09 15:03:56 +08:00 коммит произвёл GitHub
Родитель 8a226c5eca
Коммит f1325580e0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 83 добавлений и 1 удалений

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

@ -19,6 +19,8 @@ export * from 'vscode-azureextensionui';
export { activateInternal, deactivateInternal } from './src/extension';
export { ext } from './src/extensionVariables';
export { AzureAccountTreeItem } from './src/tree/AzureAccountTreeItem';
export { StorageAccountTreeItem } from './src/tree/StorageAccountTreeItem';
export { delay } from './src/utils/delay';
export { getRandomHexString } from './src/utils/stringUtils';
// NOTE: The auto-fix action "source.organizeImports" does weird things with this file, but there doesn't seem to be a way to disable it on a per-file basis so we'll just let it happen

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

@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { StorageAccount } from '@azure/arm-storage/esm/models';
import { HttpOperationResponse, ServiceClient } from '@azure/ms-rest-js';
import * as assert from 'assert';
import * as path from 'path';
import * as vscode from 'vscode';
import { createGenericClient, delay, ext, getRandomHexString, IActionContext, StorageAccountTreeItem } from '../../extension.bundle';
import { longRunningTestsEnabled, testUserInput } from '../global.test';
import { resourceGroupsToDelete, webSiteClient } from './global.resource.test';
suite('Deploy', function (this: Mocha.Suite): void {
this.timeout(3 * 60 * 1000);
suiteSetup(function (this: Mocha.Context): void {
if (!longRunningTestsEnabled) {
this.skip();
}
});
test("deployStaticWebsite", async () => {
const resourceName: string = getRandomHexString().toLowerCase();
resourceGroupsToDelete.push(resourceName);
const context: IActionContext = { telemetry: { properties: {}, measurements: {} }, errorHandling: { issueProperties: {} }, ui: testUserInput, valuesToMask: [] };
const testFolderPath: string = getWorkspacePath('html-hello-world');
await testUserInput.runWithInputs([testFolderPath, /create new storage account/i, resourceName], async () => {
await vscode.commands.executeCommand('azureStorage.deployStaticWebsite');
});
const createdAccount: StorageAccount = await webSiteClient.storageAccounts.getProperties(resourceName, resourceName);
const webUrl: string | undefined = (<StorageAccountTreeItem>await ext.tree.findTreeItem(<string>createdAccount.id, context)).root.primaryEndpoints?.web;
const client: ServiceClient = await createGenericClient();
await validateWebSite(webUrl, client, 60 * 1000, 1000);
})
});
// The workspace folder that vscode is opened against for tests
function getWorkspacePath(testWorkspaceName: string): string {
let workspacePath: string = '';
const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length === 0) {
throw new Error("No workspace is open");
} else {
for (const projectFolder of workspaceFolders) {
if (projectFolder.name === testWorkspaceName) {
workspacePath = projectFolder.uri.fsPath;
}
}
assert.strictEqual(path.basename(workspacePath), testWorkspaceName, "Opened against an unexpected workspace.");
return workspacePath;
}
}
// Polling to send the request within the maximum time
async function validateWebSite(webUrl: string | undefined, client: ServiceClient, maximumValidationMs: number, pollingMs: number) {
const endTime: number = Date.now() + maximumValidationMs;
let response: HttpOperationResponse;
// eslint-disable-next-line no-constant-condition
while (true) {
response = await client.sendRequest({ method: 'GET', url: webUrl });
if (Date.now() > endTime || response.status == 200) {
break;
}
await delay(pollingMs);
}
assert.ok(response.bodyAsText && response.bodyAsText.includes('Hello World!'));
}

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

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

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

@ -1,7 +1,7 @@
{
"folders": [
{
"path": "../testWorkspace"
"path": "./nightly/testFolder/html-hello-world"
}
],
"settings": {}