From d28b286943c08ea440f652b01976095513ceda82 Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:30:37 -0700 Subject: [PATCH 1/7] Fix azureResourceWebAppActions --- .vscode/launch.json | 4 +- extension.bundle.ts | 1 - src/extensionVariables.ts | 2 - src/tree/AzureAccountTreeItem.ts | 18 ------ .../azureResourceWebAppActions.test.ts | 26 +++++---- test/nightly/deploy.test.ts | 4 +- test/nightly/global.nightly.test.ts | 56 +++++++++++++++++++ test/nightly/global.resource.test.ts | 35 ------------ 8 files changed, 74 insertions(+), 72 deletions(-) delete mode 100644 src/tree/AzureAccountTreeItem.ts create mode 100644 test/nightly/global.nightly.test.ts delete mode 100644 test/nightly/global.resource.test.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index c4302e54b..92190e496 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -74,7 +74,7 @@ "MOCHA_timeout": "0", // Disable time-outs "DEBUGTELEMETRY": "v", "NODE_DEBUG": "", - "ENABLE_LONG_RUNNING_TESTS": "" + "AzCode_UseAzureFederatedCredentials": "true" } }, { @@ -97,7 +97,7 @@ "DEBUGTELEMETRY": "v", "NODE_DEBUG": "", "DEBUG_WEBPACK": "1", - "ENABLE_LONG_RUNNING_TESTS": "" + "AzCode_UseAzureFederatedCredentials": "" } } ] diff --git a/extension.bundle.ts b/extension.bundle.ts index f903f673d..45fe5e5b6 100644 --- a/extension.bundle.ts +++ b/extension.bundle.ts @@ -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'; diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index d46304a24..501943145 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -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 @@ -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; } diff --git a/src/tree/AzureAccountTreeItem.ts b/src/tree/AzureAccountTreeItem.ts deleted file mode 100644 index a42b0ac6e..000000000 --- a/src/tree/AzureAccountTreeItem.ts +++ /dev/null @@ -1,18 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { AzureAccountTreeItemBase } from '@microsoft/vscode-azext-azureutils'; -import { type ISubscriptionContext } from '@microsoft/vscode-azext-utils'; -import { SubscriptionTreeItem } from './SubscriptionTreeItem'; - -export class AzureAccountTreeItem extends AzureAccountTreeItemBase { - public constructor(testAccount?: {}) { - super(undefined, testAccount); - } - - public createSubscriptionTreeItem(root: ISubscriptionContext): SubscriptionTreeItem { - return new SubscriptionTreeItem(this, root); - } -} diff --git a/test/nightly/azureResourceWebAppActions.test.ts b/test/nightly/azureResourceWebAppActions.test.ts index 5940ac46a..dbe0d7634 100644 --- a/test/nightly/azureResourceWebAppActions.test.ts +++ b/test/nightly/azureResourceWebAppActions.test.ts @@ -9,10 +9,12 @@ 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 azcodePrefix: 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; @@ -22,12 +24,12 @@ suite('Web App actions', function (this: Mocha.Suite): void { if (!longRunningTestsEnabled) { this.skip(); } - resourceName = getRandomHexString(); + resourceName = azcodePrefix + 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(), 'Enabled', '$(plus) Create new Application Insights resource', resourceName]; + resourceGroupsToDelete.add(resourceName); await runWithTestActionContext('CreateWebAppAdvanced', async context => { await context.ui.runWithInputs(testInputs, async () => { await createWebAppAdvanced(context); @@ -38,12 +40,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 = azcodePrefix + getRandomHexString(6); + const webAppName: string = azcodePrefix + getRandomHexString(6); + const appServicePlanName: string = azcodePrefix + getRandomHexString(6); + const applicationInsightsName: string = azcodePrefix + 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); diff --git a/test/nightly/deploy.test.ts b/test/nightly/deploy.test.ts index 20db9e280..e491ec1f7 100644 --- a/test/nightly/deploy.test.ts +++ b/test/nightly/deploy.test.ts @@ -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 { /** @@ -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 { 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) { diff --git a/test/nightly/global.nightly.test.ts b/test/nightly/global.nightly.test.ts new file mode 100644 index 000000000..eb3d0cb53 --- /dev/null +++ b/test/nightly/global.nightly.test.ts @@ -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(); + +suiteSetup(async function (this: Mocha.Context): Promise { + 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 { + if (!longRunningTestsEnabled) { + return; + } + + this.timeout(10 * 60 * 1000); + await deleteResourceGroups(); +}); + +async function deleteResourceGroups(): Promise { + const context: TestActionContext = await createTestActionContext(); + const rgClient: ResourceManagementClient = createAzureClient([context, subscriptionContext], ResourceManagementClient); + + await Promise.all(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}".`); + })); +} diff --git a/test/nightly/global.resource.test.ts b/test/nightly/global.resource.test.ts deleted file mode 100644 index 45f9b6ecb..000000000 --- a/test/nightly/global.resource.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 { createTestActionContext, TestAzureAccount } from '@microsoft/vscode-azext-dev'; -import * as vscode from 'vscode'; -import { AzureAccountTreeItem, createWebSiteClient, ext, type ISubscriptionContext } from '../../extension.bundle'; -import { longRunningTestsEnabled } from '../global.test'; - -export let testAccount: TestAzureAccount; -export let webSiteClient: WebSiteManagementClient; -export const resourceGroupsToDelete: string[] = []; - -suiteSetup(async function (this: Mocha.Context): Promise { - this.skip(); - if (longRunningTestsEnabled) { - this.timeout(2 * 60 * 1000); - testAccount = new TestAzureAccount(vscode); - await testAccount.signIn(); - ext.azureAccountTreeItem = new AzureAccountTreeItem(testAccount); - webSiteClient = await createWebSiteClient([await createTestActionContext(), testAccount.getSubscriptionContext()]); - } -}); - -suiteTeardown(async function (this: Mocha.Context): Promise { - if (longRunningTestsEnabled) { - this.timeout(10 * 60 * 1000); - // await Promise.all(resourceGroupsToDelete.map(async resource => { - // await beginDeleteResourceGroup(resource); - // })); - // ext.azureAccountTreeItem.dispose(); - } -}); From cf0c47b84cc76b6f7672780da121c43c6509a6c7 Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:44:47 -0700 Subject: [PATCH 2/7] Update resource name --- test/nightly/azureResourceWebAppActions.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/nightly/azureResourceWebAppActions.test.ts b/test/nightly/azureResourceWebAppActions.test.ts index dbe0d7634..a9c495cb4 100644 --- a/test/nightly/azureResourceWebAppActions.test.ts +++ b/test/nightly/azureResourceWebAppActions.test.ts @@ -12,7 +12,7 @@ import { longRunningTestsEnabled } from '../global.test'; import { getRotatingPricingTier } from './getRotatingValue'; import { resourceGroupsToDelete, webSiteClient } from './global.nightly.test'; -const azcodePrefix: string = 'azc-app'; +const azcodeResourcePrefix: string = 'azc-app'; suite.only('Web App actions', function (this: Mocha.Suite): void { this.timeout(6 * 60 * 1000); @@ -24,7 +24,7 @@ suite.only('Web App actions', function (this: Mocha.Suite): void { if (!longRunningTestsEnabled) { this.skip(); } - resourceName = azcodePrefix + getRandomHexString(6); + resourceName = azcodeResourcePrefix + getRandomHexString(6); }); test(`Create New ${WebsiteOS0} Web App (Advanced)`, async () => { @@ -40,10 +40,10 @@ suite.only('Web App actions', function (this: Mocha.Suite): void { }); test(`Create New ${WebsiteOS1} Web App (Advanced)`, async () => { - const resourceGroupName: string = azcodePrefix + getRandomHexString(6); - const webAppName: string = azcodePrefix + getRandomHexString(6); - const appServicePlanName: string = azcodePrefix + getRandomHexString(6); - const applicationInsightsName: string = azcodePrefix + getRandomHexString(6); + 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 => { From 1917f762bbd78c60877a7d4e6381f3f92c1aefb6 Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:45:57 -0700 Subject: [PATCH 3/7] allSettled --- test/nightly/global.nightly.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nightly/global.nightly.test.ts b/test/nightly/global.nightly.test.ts index eb3d0cb53..e3c975e97 100644 --- a/test/nightly/global.nightly.test.ts +++ b/test/nightly/global.nightly.test.ts @@ -44,7 +44,7 @@ async function deleteResourceGroups(): Promise { const context: TestActionContext = await createTestActionContext(); const rgClient: ResourceManagementClient = createAzureClient([context, subscriptionContext], ResourceManagementClient); - await Promise.all(Array.from(resourceGroupsToDelete).map(async resourceGroup => { + await Promise.allSettled(Array.from(resourceGroupsToDelete).map(async resourceGroup => { if (!(await rgClient.resourceGroups.checkExistence(resourceGroup)).body) { return; } From 6a6812b151b6965ec55019e41b84d9a740b0cf28 Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:02:52 -0700 Subject: [PATCH 4/7] Register extension variables --- test/global.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/global.test.ts b/test/global.test.ts index 15d825a98..099185a38 100644 --- a/test/global.test.ts +++ b/test/global.test.ts @@ -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'; export const longRunningTestsEnabled: boolean = !/^(false|0)?$/i.test(process.env.AzCode_UseAzureFederatedCredentials || ''); @@ -13,7 +14,10 @@ export const longRunningTestsEnabled: boolean = !/^(false|0)?$/i.test(process.en suiteSetup(async function (this: Mocha.Context): Promise { 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 From 716353b7c3446b7fbe70bf8fe60ffc9a80e0e18c Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:25:36 -0700 Subject: [PATCH 5/7] use disabled --- test/nightly/azureResourceWebAppActions.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nightly/azureResourceWebAppActions.test.ts b/test/nightly/azureResourceWebAppActions.test.ts index a9c495cb4..9408f63e7 100644 --- a/test/nightly/azureResourceWebAppActions.test.ts +++ b/test/nightly/azureResourceWebAppActions.test.ts @@ -28,7 +28,7 @@ suite.only('Web App actions', function (this: Mocha.Suite): void { }); test(`Create New ${WebsiteOS0} Web App (Advanced)`, async () => { - const testInputs: (string | RegExp)[] = [resourceName, '$(plus) Create new resource group', resourceName, ...getInput(WebsiteOS0), 'East US', '$(plus) Create new App Service plan', resourceName, getRotatingPricingTier(), 'Enabled', '$(plus) Create new Application Insights resource', 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 () => { From d3f2d5921ac0c4da76c47d2446218780a94dbd42 Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:35:18 -0700 Subject: [PATCH 6/7] Formatting --- test/nightly/azureResourceWebAppActions.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/nightly/azureResourceWebAppActions.test.ts b/test/nightly/azureResourceWebAppActions.test.ts index 9408f63e7..bf94b97ad 100644 --- a/test/nightly/azureResourceWebAppActions.test.ts +++ b/test/nightly/azureResourceWebAppActions.test.ts @@ -16,6 +16,7 @@ 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; From 3eeaa2f6e11068953466a6d8e67224fa866b889d Mon Sep 17 00:00:00 2001 From: MicroFish91 <40250218+MicroFish91@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:59:55 -0700 Subject: [PATCH 7/7] Revert launch json --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1cdf688ce..db186254f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -97,7 +97,7 @@ "DEBUGTELEMETRY": "v", "NODE_DEBUG": "", "DEBUG_WEBPACK": "1", - "AzCode_UseAzureFederatedCredentials": "" + "ENABLE_LONG_RUNNING_TESTS": "" } } ]