Create Cosmos DB account (#1203)
* Create account * Update code according to the comments
This commit is contained in:
Родитель
cecedc4e63
Коммит
9efba7d165
|
@ -20,6 +20,7 @@ export { activateInternal, deactivateInternal } from './src/extension';
|
|||
export { ext } from './src/extensionVariables';
|
||||
export * from './src/utils/array';
|
||||
export { AttachedAccountsTreeItem, MONGO_CONNECTION_EXPECTED } from './src/tree/AttachedAccountsTreeItem';
|
||||
export { AzureAccountTreeItemWithAttached } from './src/tree/AzureAccountTreeItemWithAttached';
|
||||
export { parseDocDBConnectionString } from './src/docdb/docDBConnectionStrings';
|
||||
export { emulatorPassword } from './src/constants';
|
||||
export { getDocumentTreeItemLabel } from './src/utils/vscodeUtils';
|
||||
|
@ -28,6 +29,7 @@ export { MongoCommand } from './src/mongo/MongoCommand';
|
|||
export { getAllCommandsFromText, getCommandFromTextAtLocation } from './src/mongo/MongoScrapbook';
|
||||
export { rejectOnTimeout, valueOnTimeout } from './src/utils/timeout';
|
||||
export { improveError } from './src/utils/improveError';
|
||||
export { randomUtils } from './src/utils/randomUtils';
|
||||
export { parseError } from 'vscode-azureextensionui';
|
||||
export { MongoShell } from './src/mongo/MongoShell';
|
||||
export { wrapError } from './src/utils/wrapError';
|
||||
|
|
|
@ -7,6 +7,7 @@ import { ExtensionContext, TreeView } from "vscode";
|
|||
import { AzExtTreeDataProvider, AzExtTreeItem, IAzExtOutputChannel, IAzureUserInput, ITelemetryReporter } from "vscode-azureextensionui";
|
||||
import { MongoDatabaseTreeItem } from "./mongo/tree/MongoDatabaseTreeItem";
|
||||
import { AttachedAccountsTreeItem } from "./tree/AttachedAccountsTreeItem";
|
||||
import { AzureAccountTreeItemWithAttached } from "./tree/AzureAccountTreeItemWithAttached";
|
||||
|
||||
/**
|
||||
* Namespace for common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
|
||||
|
@ -22,6 +23,7 @@ export namespace ext {
|
|||
export let attachedAccountsNode: AttachedAccountsTreeItem;
|
||||
// tslint:disable-next-line: strict-boolean-expressions
|
||||
export let ignoreBundle: boolean = !/^(false|0)?$/i.test(process.env.AZCODE_COSMOSDB_IGNORE_BUNDLE || '');
|
||||
export let azureAccountTreeItem: AzureAccountTreeItemWithAttached;
|
||||
|
||||
export namespace settingsKeys {
|
||||
export const mongoShellPath = 'mongo.shell.path';
|
||||
|
|
|
@ -9,8 +9,8 @@ import { AttachedAccountsTreeItem } from './AttachedAccountsTreeItem';
|
|||
import { SubscriptionTreeItem } from './SubscriptionTreeItem';
|
||||
|
||||
export class AzureAccountTreeItemWithAttached extends AzureAccountTreeItemBase {
|
||||
public constructor() {
|
||||
super();
|
||||
public constructor(testAccount?: {}) {
|
||||
super(undefined, testAccount);
|
||||
ext.attachedAccountsNode = new AttachedAccountsTreeItem(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,17 @@
|
|||
|
||||
import { IHookCallbackContext } from 'mocha';
|
||||
import * as vscode from 'vscode';
|
||||
import { TestUserInput, TestOutputChannel } from 'vscode-azureextensiondev';
|
||||
import { ext } from '../extension.bundle';
|
||||
|
||||
// tslint:disable-next-line:strict-boolean-expressions export-name
|
||||
export let longRunningTestsEnabled: boolean = !/^(false|0)?$/i.test(process.env.ENABLE_LONG_RUNNING_TESTS || '');
|
||||
export const testUserInput: TestUserInput = new TestUserInput(vscode);
|
||||
|
||||
// Runs before all tests
|
||||
suiteSetup(async function (this: IHookCallbackContext): Promise<void> {
|
||||
this.timeout(120 * 1000);
|
||||
this.timeout(2 * 60 * 1000);
|
||||
await vscode.commands.executeCommand('cosmosDB.refresh'); // activate the extension before tests begin
|
||||
ext.outputChannel = new TestOutputChannel();
|
||||
ext.ui = testUserInput;
|
||||
});
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CosmosDBManagementModels } from 'azure-arm-cosmosdb';
|
||||
import { IHookCallbackContext, ISuiteCallbackContext } from 'mocha';
|
||||
import * as vscode from 'vscode';
|
||||
import { randomUtils } from '../../extension.bundle';
|
||||
import { longRunningTestsEnabled, testUserInput } from '../global.test';
|
||||
import { resourceGroupsToDelete, client } from './global.resource.test';
|
||||
|
||||
suite('MongoDB action', async function (this: ISuiteCallbackContext): Promise<void> {
|
||||
this.timeout(20 * 60 * 1000);
|
||||
|
||||
suiteSetup(async function (this: IHookCallbackContext): Promise<void> {
|
||||
if (!longRunningTestsEnabled) {
|
||||
this.skip();
|
||||
}
|
||||
this.timeout(2 * 60 * 1000);
|
||||
});
|
||||
|
||||
test('create Cosmos DB account', async () => {
|
||||
const resourceGroupName: string = randomUtils.getRandomHexString(12);
|
||||
// Cosmos DB account must have lower case name
|
||||
const accountName: string = randomUtils.getRandomHexString(12).toLowerCase();
|
||||
resourceGroupsToDelete.push(resourceGroupName);
|
||||
const testInputs: string[] = [accountName, 'MongoDB', '$(plus) Create new resource group', resourceGroupName, 'West US'];
|
||||
await testUserInput.runWithInputs(testInputs, async () => {
|
||||
await vscode.commands.executeCommand('cosmosDB.createAccount');
|
||||
});
|
||||
const createAccount: CosmosDBManagementModels.DatabaseAccount | undefined = await client.databaseAccounts.get(resourceGroupName, accountName);
|
||||
assert.ok(createAccount);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ResourceManagementClient } from 'azure-arm-resource';
|
||||
import { CosmosDBManagementClient } from 'azure-arm-cosmosdb';
|
||||
import { IHookCallbackContext } from 'mocha';
|
||||
import * as vscode from 'vscode';
|
||||
import { ext, AzureAccountTreeItemWithAttached } from '../../extension.bundle';
|
||||
import { longRunningTestsEnabled } from '../global.test';
|
||||
import { AzExtTreeDataProvider, createAzureClient } from 'vscode-azureextensionui';
|
||||
import { TestAzureAccount } from 'vscode-azureextensiondev';
|
||||
|
||||
export let testAccount: TestAzureAccount;
|
||||
export let client: CosmosDBManagementClient;
|
||||
export const resourceGroupsToDelete: string[] = [];
|
||||
|
||||
suiteSetup(async function (this: IHookCallbackContext): Promise<void> {
|
||||
if (!longRunningTestsEnabled) {
|
||||
this.skip();
|
||||
}
|
||||
|
||||
this.timeout(2 * 60 * 1000);
|
||||
testAccount = new TestAzureAccount(vscode);
|
||||
await testAccount.signIn();
|
||||
ext.azureAccountTreeItem = new AzureAccountTreeItemWithAttached(testAccount);
|
||||
ext.tree = new AzExtTreeDataProvider(ext.azureAccountTreeItem, 'cosmosDB.loadMore');
|
||||
client = createAzureClient(testAccount.getSubscriptionContext(), CosmosDBManagementClient);
|
||||
});
|
||||
|
||||
suiteTeardown(async function (this: IHookCallbackContext): Promise<void> {
|
||||
if (!longRunningTestsEnabled) {
|
||||
this.skip();
|
||||
}
|
||||
this.timeout(10 * 60 * 1000);
|
||||
await deleteResourceGroups();
|
||||
ext.azureAccountTreeItem.dispose();
|
||||
});
|
||||
|
||||
async function deleteResourceGroups(): Promise<void> {
|
||||
const client: ResourceManagementClient = createAzureClient(testAccount.getSubscriptionContext(), ResourceManagementClient);
|
||||
await Promise.all(resourceGroupsToDelete.map(async resourceGroup => {
|
||||
if (await client.resourceGroups.checkExistence(resourceGroup)) {
|
||||
console.log(`Deleting resource group "${resourceGroup}"...`);
|
||||
await client.resourceGroups.beginDeleteMethod(resourceGroup);
|
||||
console.log(`Resource group "${resourceGroup}" deleted.`);
|
||||
} else {
|
||||
// If the test failed, the resource group might not actually exist
|
||||
console.log(`Ignoring resource group "${resourceGroup}" because it does not exist.`);
|
||||
}
|
||||
}));
|
||||
}
|
Загрузка…
Ссылка в новой задаче