-
Notifications
You must be signed in to change notification settings - Fork 28
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 long running tests and use new federated credentials for testing #864
Changes from 52 commits
f8b7ada
666331d
ab7d2b3
6f26be0
b430191
e736093
5702f73
818c9d8
fb86ea2
70ea454
565b639
914981e
a3f8c03
88ddc26
b02c6eb
1461993
e39f237
703699a
383bf52
d09823b
bfb4815
3e5a7fe
dcd9520
941b5ba
ae77264
1e6b7a8
12e4fd7
1dde188
511c8e2
5b043ed
8d072e8
8a34174
b676b40
9d443e2
7a0c045
7870694
53b89af
c222174
082f9fa
96ef64f
c5f542b
5940e78
6b345a3
53a928d
8108fad
717d7e1
7619718
aa343d7
c73b107
9ba3554
efaf5d9
46ae5d4
7e62b84
adf99a1
8c5d849
2bd383d
f33e2dc
82410be
9dc02eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"ms-vscode.azure-account" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer need this recommendation |
||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { gulp_installAzureAccount, gulp_webpack } from '@microsoft/vscode-azext-dev'; | ||
import { gulp_webpack } from '@microsoft/vscode-azext-dev'; | ||
import * as fs from 'fs/promises'; | ||
import * as gulp from 'gulp'; | ||
import * as path from 'path'; | ||
|
@@ -50,6 +50,5 @@ async function cleanReadme(): Promise<void> { | |
|
||
exports['webpack-dev'] = gulp.series(prepareForWebpack, () => gulp_webpack('development')); | ||
exports['webpack-prod'] = gulp.series(prepareForWebpack, () => gulp_webpack('production')); | ||
exports.preTest = gulp_installAzureAccount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer need to install Azure Account before tests |
||
exports.listIcons = listIcons; | ||
exports.cleanReadme = cleanReadme; |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type Location } from '@azure/arm-resources-subscriptions'; | ||
import { createTestActionContext, runWithTestActionContext } from '@microsoft/vscode-azext-dev'; | ||
import { AzExtParentTreeItem, createResourceClient, createResourceGroup, deleteResourceGroupV2, ext, IActionContext, LocationListStep, randomUtils, settingUtils, SubscriptionItem } from '../../extension.bundle'; | ||
import { longRunningTestsEnabled } from "../global.test"; | ||
import assert = require("assert"); | ||
|
||
let rgName: string; | ||
let locations: Location[]; | ||
let testSubscription: SubscriptionItem; | ||
|
||
suite('Resource CRUD Operations', function (this: Mocha.Suite): void { | ||
this.timeout(7 * 60 * 1000); | ||
|
||
suiteSetup(async function (this: Mocha.Context): Promise<void> { | ||
if (!longRunningTestsEnabled) { | ||
this.skip(); | ||
} | ||
|
||
ext.testing.overrideAzureServiceFactory = undefined; | ||
ext.testing.overrideAzureSubscriptionProvider = undefined; | ||
|
||
const subscriptionTreeItems = await ext.appResourceTree.getChildren() as unknown as SubscriptionItem[]; | ||
if (subscriptionTreeItems.length > 0) { | ||
const testContext = await createTestActionContext(); | ||
testSubscription = subscriptionTreeItems[0] as SubscriptionItem; | ||
const context = { ...testContext, ...testSubscription.subscription }; | ||
locations = await LocationListStep.getLocations(context); | ||
} | ||
|
||
rgName = randomUtils.getRandomHexString(12); | ||
}); | ||
|
||
test('Create Resource Group (single)', async () => { | ||
await runWithTestActionContext('createResourceGroup', async context => { | ||
const testInputs: (string | RegExp)[] = [rgName, locations[0].displayName!]; | ||
await context.ui.runWithInputs(testInputs, async () => { | ||
await createResourceGroup(context, testSubscription); | ||
}); | ||
|
||
assert.ok(await resourceGroupExists(context, rgName)); | ||
}); | ||
}); | ||
|
||
test('Create Resource Groups (all locations)', async () => { | ||
await Promise.all(locations.map(async l => { | ||
await runWithTestActionContext('createResourceGroup', async context => { | ||
const testInputs: (string | RegExp)[] = [`${rgName}-${l.name}`, l.displayName!]; | ||
await context.ui.runWithInputs(testInputs, async () => { | ||
await createResourceGroup(context, testSubscription); | ||
}); | ||
|
||
assert.ok(await resourceGroupExists(context, `${rgName}-${l.name}`)); | ||
}); | ||
})); | ||
}); | ||
|
||
test('Get Resources', async () => { | ||
const subscriptionTreeItems = await ext.appResourceTree.getChildren(); | ||
assert.ok(subscriptionTreeItems.length > 0); | ||
for (const subscription of subscriptionTreeItems) { | ||
const groupTreeItems = await ext.appResourceTree.getChildren(subscription as AzExtParentTreeItem); | ||
await Promise.all(groupTreeItems.map(async g => { | ||
const children = await ext.appResourceTree.getChildren(g as AzExtParentTreeItem); | ||
console.log(children); | ||
})); | ||
} | ||
|
||
assert.ok(true); | ||
}); | ||
|
||
test('Delete Resource (EnterName) - Fails when invalid', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'EnterName'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([rgName, 'rgName'], async () => { | ||
try { | ||
await deleteResourceGroupV2(context); | ||
} catch (_) { | ||
console.debug('Expected error: ', _); | ||
// expected to fail here | ||
} | ||
assert.ok(await resourceGroupExists(context, rgName)); | ||
}); | ||
}); | ||
}); | ||
|
||
test('Delete Resource (EnterName)', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'EnterName'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([rgName, rgName], async () => { | ||
await deleteResourceGroupV2(context); | ||
}); | ||
|
||
// ext.azureResourceProvider.onDidChangeResource!(async e => { | ||
// console.log(e); | ||
// assert.ok(!(await resourceGroupExists(context, rgName))); | ||
// }) | ||
}); | ||
|
||
}); | ||
|
||
test('Delete Resource (ClickButton)', async () => { | ||
await settingUtils.updateGlobalSetting('deleteConfirmation', 'ClickButton'); | ||
const deleteArray: string[] = Array(locations.length).fill('Delete'); | ||
await runWithTestActionContext('Delete Resource', async context => { | ||
await context.ui.runWithInputs([new RegExp(`${rgName}-`), ...deleteArray], async () => { | ||
await deleteResourceGroupV2(context); | ||
}); | ||
}); | ||
|
||
assert.ok(true); | ||
}); | ||
}); | ||
|
||
async function resourceGroupExists(context: IActionContext, rgName: string): Promise<boolean> { | ||
const client = await createResourceClient([context, testSubscription.subscription]); | ||
try { | ||
await client.resourceGroups.get(rgName); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { longRunningTestsEnabled } from '../global.test'; | ||
|
||
export const resourceGroupsToDelete: string[] = []; | ||
|
||
// Runs before all nightly tests | ||
suiteSetup(async function (this: Mocha.Context): Promise<void> { | ||
// TODO: Use other environment variables to determine if the tests should be run | ||
if (longRunningTestsEnabled) { | ||
this.timeout(2 * 60 * 1000); | ||
await vscode.commands.executeCommand('azureResourceGroups.logIn'); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the rest of the file, this pipeline file is only run when scheduled for nightly builds. Normal build pipelines that occur on PRs are done through GitHub Actions and not through this file. This is why
useAzureFederatedCredentials
is always set totrue
. For completeness sake, we could also set it to only be true if the build reason isSchedule
, but that would make it harder to test manually for any reason