Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nightly tests and fix azureResourceWebAppActions tests #2650

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export * as constants from './src/constants';
// Export activate/deactivate for main.js
export { activateInternal, deactivateInternal } from './src/extension';
export { ext } from './src/extensionVariables';
export { AzureAccountTreeItem } from './src/tree/AzureAccountTreeItem';
export { SiteTreeItem } from './src/tree/SiteTreeItem';
export * from './src/utils/azureClients';
export { getRandomHexString } from './src/utils/randomUtils';
Expand Down
2 changes: 0 additions & 2 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { type IAzExtOutputChannel, type IExperimentationServiceAdapter } from "@
import { type AzureHostExtensionApi } from "@microsoft/vscode-azext-utils/hostapi";
import { type ExtensionContext } from "vscode";
import { type AppServiceFileSystem } from "./AppServiceFileSystem";
import { type AzureAccountTreeItem } from "./tree/AzureAccountTreeItem";

/**
* Namespace for common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
Expand All @@ -19,7 +18,6 @@ export namespace ext {
export let fileSystem: AppServiceFileSystem;
export const prefix: string = 'appService';

export let azureAccountTreeItem: AzureAccountTreeItem;
export let experimentationService: IExperimentationServiceAdapter;
export let rgApi: AzureHostExtensionApi;
}
18 changes: 0 additions & 18 deletions src/tree/AzureAccountTreeItem.ts

This file was deleted.

6 changes: 5 additions & 1 deletion test/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { registerAzureUtilsExtensionVariables } from '@microsoft/vscode-azext-azureutils';
import { TestOutputChannel, TestUserInput } from '@microsoft/vscode-azext-dev';
import * as vscode from 'vscode';
import { ext, registerOnActionStartHandler } from '../extension.bundle';
import { ext, registerOnActionStartHandler, registerUIExtensionVariables } from '../extension.bundle';

const longRunningLocalTestsEnabled: boolean = !/^(false|0)?$/i.test(process.env.AzCode_EnableLongRunningTestsLocal || '');
const longRunningRemoteTestsEnabled: boolean = !/^(false|0)?$/i.test(process.env.AzCode_UseAzureFederatedCredentials || '');
Expand All @@ -16,7 +17,10 @@ export const longRunningTestsEnabled: boolean = longRunningLocalTestsEnabled ||
suiteSetup(async function (this: Mocha.Context): Promise<void> {
this.timeout(120 * 1000);
await vscode.commands.executeCommand('appService.Refresh'); // activate the extension before tests begin

ext.outputChannel = new TestOutputChannel();
registerUIExtensionVariables(ext);
registerAzureUtilsExtensionVariables(ext);

registerOnActionStartHandler(context => {
// Use `TestUserInput` by default so we get an error if an unexpected call to `context.ui` occurs, rather than timing out
Expand Down
27 changes: 15 additions & 12 deletions test/nightly/azureResourceWebAppActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { runWithTestActionContext } from '@microsoft/vscode-azext-dev';
import * as assert from 'assert';
import { DialogResponses, addAppSetting, constants, createWebAppAdvanced, deleteAppSetting, deleteWebApp, editScmType, getRandomHexString } from '../../extension.bundle';
import { longRunningTestsEnabled } from '../global.test';
import { getRotatingLocation, getRotatingPricingTier } from './getRotatingValue';
import { resourceGroupsToDelete, webSiteClient } from './global.resource.test';
import { getRotatingPricingTier } from './getRotatingValue';
import { resourceGroupsToDelete, webSiteClient } from './global.nightly.test';

suite('Web App actions', function (this: Mocha.Suite): void {
const azcodeResourcePrefix: string = 'azc-app';

suite.only('Web App actions', function (this: Mocha.Suite): void {
this.timeout(6 * 60 * 1000);

let resourceName: string;
const WebsiteOS0: WebsiteOS = (new Date().getDate()) % 2 === 0 ? WebsiteOS.linux : WebsiteOS.windows;
const WebsiteOS1: WebsiteOS = WebsiteOS0 === WebsiteOS.windows ? WebsiteOS.linux : WebsiteOS.windows;
Expand All @@ -22,12 +25,12 @@ suite('Web App actions', function (this: Mocha.Suite): void {
if (!longRunningTestsEnabled) {
this.skip();
}
resourceName = getRandomHexString();
resourceName = azcodeResourcePrefix + getRandomHexString(6);
});

test(`Create New ${WebsiteOS0} Web App (Advanced)`, async () => {
const testInputs: (string | RegExp)[] = [resourceName, '$(plus) Create new resource group', resourceName, ...getInput(WebsiteOS0), getRotatingLocation(), '$(plus) Create new App Service plan', resourceName, getRotatingPricingTier(), '$(plus) Create new Application Insights resource', resourceName];
resourceGroupsToDelete.push(resourceName);
const testInputs: (string | RegExp)[] = [resourceName, '$(plus) Create new resource group', resourceName, ...getInput(WebsiteOS0), 'East US', '$(plus) Create new App Service plan', resourceName, getRotatingPricingTier(), 'Disabled', '$(plus) Create new Application Insights resource', resourceName];
resourceGroupsToDelete.add(resourceName);
await runWithTestActionContext('CreateWebAppAdvanced', async context => {
await context.ui.runWithInputs(testInputs, async () => {
await createWebAppAdvanced(context);
Expand All @@ -38,12 +41,12 @@ suite('Web App actions', function (this: Mocha.Suite): void {
});

test(`Create New ${WebsiteOS1} Web App (Advanced)`, async () => {
const resourceGroupName: string = getRandomHexString();
const webAppName: string = getRandomHexString();
const appServicePlanName: string = getRandomHexString();
const applicationInsightsName: string = getRandomHexString();
resourceGroupsToDelete.push(resourceGroupName);
const testInputs: (string | RegExp)[] = [webAppName, '$(plus) Create new resource group', resourceGroupName, ...getInput(WebsiteOS1), getRotatingLocation(), '$(plus) Create new App Service plan', appServicePlanName, getRotatingPricingTier(), '$(plus) Create new Application Insights resource', applicationInsightsName];
const resourceGroupName: string = azcodeResourcePrefix + getRandomHexString(6);
const webAppName: string = azcodeResourcePrefix + getRandomHexString(6);
const appServicePlanName: string = azcodeResourcePrefix + getRandomHexString(6);
const applicationInsightsName: string = azcodeResourcePrefix + getRandomHexString(6);
resourceGroupsToDelete.add(resourceGroupName);
const testInputs: (string | RegExp)[] = [webAppName, '$(plus) Create new resource group', resourceGroupName, ...getInput(WebsiteOS1), 'West US', '$(plus) Create new App Service plan', appServicePlanName, getRotatingPricingTier(), '$(plus) Create new Application Insights resource', applicationInsightsName];
await runWithTestActionContext('CreateWebAppAdvanced', async context => {
await context.ui.runWithInputs(testInputs, async () => {
await createWebAppAdvanced(context);
Expand Down
4 changes: 2 additions & 2 deletions test/nightly/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as vscode from 'vscode';
import { createGenericClient, createWebAppAdvanced, deploy, ext, getRandomHexString, nonNullProp, type SiteTreeItem } from '../../extension.bundle';
import { longRunningTestsEnabled } from '../global.test';
import { getRotatingLocation, getRotatingPricingTier } from './getRotatingValue';
import { resourceGroupsToDelete, webSiteClient } from './global.resource.test';
import { resourceGroupsToDelete, webSiteClient } from './global.nightly.test';

interface ITestCase {
/**
Expand Down Expand Up @@ -123,7 +123,7 @@ suite('Create Web App and deploy', function (this: Mocha.Suite): void {
async function testCreateWebAppAndDeploy(os: string, promptForOs: boolean, runtime: string, workspacePath: string, expectedVersion: string, zipFile?: string): Promise<void> {
const resourceName: string = getRandomHexString();
const resourceGroupName = getRandomHexString();
resourceGroupsToDelete.push(resourceGroupName);
resourceGroupsToDelete.add(resourceGroupName);

const testInputs: (string | RegExp)[] = [resourceName, '$(plus) Create new resource group', resourceGroupName, runtime];
if (promptForOs) {
Expand Down
56 changes: 56 additions & 0 deletions test/nightly/global.nightly.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type WebSiteManagementClient } from '@azure/arm-appservice';
import { ResourceManagementClient } from '@azure/arm-resources';
import { createAzureClient } from '@microsoft/vscode-azext-azureutils';
import { createTestActionContext, type TestActionContext } from '@microsoft/vscode-azext-dev';
import { type AzureSubscription } from '@microsoft/vscode-azureresources-api';
import * as vscode from 'vscode';
import { createSubscriptionContext, createWebSiteClient, ext, subscriptionExperience, type ISubscriptionContext } from '../../extension.bundle';
import { longRunningTestsEnabled } from '../global.test';

export let subscriptionContext: ISubscriptionContext;
export let webSiteClient: WebSiteManagementClient;
export const resourceGroupsToDelete = new Set<string>();

suiteSetup(async function (this: Mocha.Context): Promise<void> {
if (!longRunningTestsEnabled) {
this.skip();
}

this.timeout(2 * 60 * 1000);
await vscode.commands.executeCommand('azureResourceGroups.logIn');

const context: TestActionContext = await createTestActionContext();
const subscription: AzureSubscription = await subscriptionExperience(context, ext.rgApi.appResourceTree);
subscriptionContext = createSubscriptionContext(subscription);

webSiteClient = await createWebSiteClient([context, subscriptionContext]);
});

suiteTeardown(async function (this: Mocha.Context): Promise<void> {
if (!longRunningTestsEnabled) {
return;
}

this.timeout(10 * 60 * 1000);
await deleteResourceGroups();
});

async function deleteResourceGroups(): Promise<void> {
const context: TestActionContext = await createTestActionContext();
const rgClient: ResourceManagementClient = createAzureClient([context, subscriptionContext], ResourceManagementClient);

await Promise.allSettled(Array.from(resourceGroupsToDelete).map(async resourceGroup => {
if (!(await rgClient.resourceGroups.checkExistence(resourceGroup)).body) {
return;
}

console.log(`Deleting resource group "${resourceGroup}"...`);
await rgClient.resourceGroups.beginDeleteAndWait(resourceGroup);
console.log(`Successfully deleted resource group "${resourceGroup}".`);
}));
}
35 changes: 0 additions & 35 deletions test/nightly/global.resource.test.ts

This file was deleted.

Loading