mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Replacing all azdata with az (#16502)
* Changed azdata to az in azcli extension and resource-deployment, and some arc. Removed user, pass, url from controller connect blade. Commented out tests. Ported over work from old branch. * Changed unit tests, all unit tests passing. Changed parameters to new ones, fixed some Controller Connect issues. * Connect data controller and create dc working. * Changed az back to azdata in necessary places in resource-deployment. * Changed notebook values and added namespace to some params. * Added some changes from PR to this branch * Changed azdata.ts to az.ts and changed subscription parameter * Brought over changes from azcli PR into this branch. * added endpoint, username, password to getIsPassword * Changed notebooks to use proper az params, hard coded in some values to verify it is working, removed some variableNames from package.json. * Changed -sc to --storage-class in notebook * Added namespace to SQL deploy, deleted dc create in api * Deleted more dc create code and uncommented findAz() with unfinished work on Do Not Ask Again. * Removed (preview) from extensions/arc and extensions/azcli excluding preview:true in package.json * Commented out install/update prompts until DoNotAskAgain is implemented * Fixed bugs: JSON Output errors are now being caught, --infrastructure now has a required UI component with dropdown options, config page loads properly, SQL create flags use full names instead of shortnames. * Adds validation to pg extensions and bug fixes (#16486) * Extensions * Server parameters * Change locaiton of postgres extensions, pr fixes * Change location of list * List spacing * Commented out Don't Ask Again prompt implementation. * Uncommented header of a test file. * Added Azure CLI arcdata extension to Prerequisites * Reverted package.json and yarn.lock * Took away casting of stderr and stdout in executeCommand. * Deleted override function for initializeFields in connectControllerDialog.ts * Removed fakeAzApi for testing and added back in (Preview) * Removed en-us from python notebook links. * Deleted azdata tool from tool tests in resource-deployment * Deleted another instance of azdata in tool test * Add back in azdata tooltype * Remove en-us * Replaced AzdataTool in typings * Reverting adding azdata tool back in * Changed Azdata to AzdataToolOld * Added back azdata tool type * Added AzdataToolOld to tool types * fix test Co-authored-by: Candice Ye <canye@microsoft.com> Co-authored-by: nasc17 <nasc@microsoft.com> Co-authored-by: nasc17 <69922333+nasc17@users.noreply.github.com> Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -1,80 +1,77 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// /*---------------------------------------------------------------------------------------------
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// * Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
// *--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { PGResourceInfo, ResourceType } from 'arc';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as should from 'should';
|
||||
import * as sinon from 'sinon';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as vscode from 'vscode';
|
||||
import { createModelViewMock } from '@microsoft/azdata-test/out/mocks/modelView/modelViewMock';
|
||||
import { ControllerModel, Registration } from '../../../models/controllerModel';
|
||||
import { PostgresModel } from '../../../models/postgresModel';
|
||||
import { PostgresConnectionStringsPage } from '../../../ui/dashboards/postgres/postgresConnectionStringsPage';
|
||||
import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
import { FakeAzdataApi } from '../../mocks/fakeAzdataApi';
|
||||
import { FakePostgresServerShowOutput } from '../../models/postgresModel.test';
|
||||
// import { PGResourceInfo, ResourceType } from 'arc';
|
||||
// import * as azExt from 'azdata-ext';
|
||||
// import * as should from 'should';
|
||||
// import * as sinon from 'sinon';
|
||||
// import * as TypeMoq from 'typemoq';
|
||||
// import * as vscode from 'vscode';
|
||||
// import { createModelViewMock } from '@microsoft/azdata-test/out/mocks/modelView/modelViewMock';
|
||||
// import { ControllerModel, Registration } from '../../../models/controllerModel';
|
||||
// import { PostgresModel } from '../../../models/postgresModel';
|
||||
// import { PostgresConnectionStringsPage } from '../../../ui/dashboards/postgres/postgresConnectionStringsPage';
|
||||
// import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
// import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
// import { FakeAzdataApi } from '../../mocks/fakeAzdataApi';
|
||||
// import { FakePostgresServerShowOutput } from '../../models/postgresModel.test';
|
||||
|
||||
describe('postgresConnectionStringsPage', function (): void {
|
||||
let controllerModel: ControllerModel;
|
||||
let postgresModel: PostgresModel;
|
||||
let azdataApi: azdataExt.IAzdataApi;
|
||||
let postgresConnectionStrings: PostgresConnectionStringsPage;
|
||||
// describe('postgresConnectionStringsPage', function (): void {
|
||||
// let controllerModel: ControllerModel;
|
||||
// let postgresModel: PostgresModel;
|
||||
// let azdataApi: azExt.IAzdataApi;
|
||||
// let postgresConnectionStrings: PostgresConnectionStringsPage;
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
// afterEach(function (): void {
|
||||
// sinon.restore();
|
||||
// });
|
||||
|
||||
beforeEach(async () => {
|
||||
// Stub the azdata CLI API
|
||||
azdataApi = new FakeAzdataApi();
|
||||
const azdataExt = TypeMoq.Mock.ofType<azdataExt.IExtension>();
|
||||
azdataExt.setup(x => x.azdata).returns(() => azdataApi);
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: azdataExt.object });
|
||||
// beforeEach(async () => {
|
||||
// // Stub the azdata CLI API
|
||||
// azdataApi = new FakeAzdataApi();
|
||||
// const azExt = TypeMoq.Mock.ofType<azExt.IExtension>();
|
||||
// azExt.setup(x => x.azdata).returns(() => azdataApi);
|
||||
// sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: azExt.object });
|
||||
|
||||
// Setup Controller Model
|
||||
controllerModel = new FakeControllerModel();
|
||||
// // Setup Controller Model
|
||||
// controllerModel = new FakeControllerModel();
|
||||
|
||||
//Stub calling azdata login and acquiring session
|
||||
sinon.stub(controllerModel, 'login').returns(Promise.resolve());
|
||||
// // Setup PostgresModel
|
||||
// const postgresResource: PGResourceInfo = { name: 'pgt', resourceType: '' };
|
||||
// const registration: Registration = { instanceName: '', state: '', instanceType: ResourceType.postgresInstances };
|
||||
// postgresModel = new PostgresModel(controllerModel, postgresResource, registration, new AzureArcTreeDataProvider(TypeMoq.Mock.ofType<vscode.ExtensionContext>().object));
|
||||
|
||||
// Setup PostgresModel
|
||||
const postgresResource: PGResourceInfo = { name: 'pgt', resourceType: '' };
|
||||
const registration: Registration = { instanceName: '', state: '', instanceType: ResourceType.postgresInstances };
|
||||
postgresModel = new PostgresModel(controllerModel, postgresResource, registration, new AzureArcTreeDataProvider(TypeMoq.Mock.ofType<vscode.ExtensionContext>().object));
|
||||
// // Setup stub of show call
|
||||
// const postgresShow = sinon.stub().returns(FakePostgresServerShowOutput);
|
||||
// sinon.stub(azdataApi, 'arc').get(() => {
|
||||
// return { postgres: { server: { show(name: string) { return postgresShow(name); } } } };
|
||||
// });
|
||||
|
||||
// Setup stub of show call
|
||||
const postgresShow = sinon.stub().returns(FakePostgresServerShowOutput);
|
||||
sinon.stub(azdataApi, 'arc').get(() => {
|
||||
return { postgres: { server: { show(name: string) { return postgresShow(name); } } } };
|
||||
});
|
||||
// // Setup the PostgresConnectionsStringsPage
|
||||
// let { modelViewMock } = createModelViewMock();
|
||||
// postgresConnectionStrings = new PostgresConnectionStringsPage(modelViewMock.object, undefined!, postgresModel);
|
||||
// });
|
||||
|
||||
// Setup the PostgresConnectionsStringsPage
|
||||
let { modelViewMock } = createModelViewMock();
|
||||
postgresConnectionStrings = new PostgresConnectionStringsPage(modelViewMock.object, undefined!, postgresModel);
|
||||
});
|
||||
// describe('getConnectionStrings', function (): void {
|
||||
|
||||
describe('getConnectionStrings', function (): void {
|
||||
// it('Strings container should be empty since postgres model has not been refreshed', async function (): Promise<void> {
|
||||
// should(postgresConnectionStrings['getConnectionStrings']()).be.empty();
|
||||
// });
|
||||
|
||||
it('Strings container should be empty since postgres model has not been refreshed', async function (): Promise<void> {
|
||||
should(postgresConnectionStrings['getConnectionStrings']()).be.empty();
|
||||
});
|
||||
// it('String contain correct ip and port', async function (): Promise<void> {
|
||||
// // Call to provide external endpoint
|
||||
// await postgresModel.refresh();
|
||||
|
||||
it('String contain correct ip and port', async function (): Promise<void> {
|
||||
// Call to provide external endpoint
|
||||
await postgresModel.refresh();
|
||||
// let endpoint = FakePostgresServerShowOutput.result.status.primaryEndpoint.split(':');
|
||||
|
||||
let endpoint = FakePostgresServerShowOutput.result.status.primaryEndpoint.split(':');
|
||||
// postgresConnectionStrings['getConnectionStrings']().forEach(k => {
|
||||
// should(k.value.includes(endpoint[0])).be.True();
|
||||
// should(k.value.includes(endpoint[1])).be.True();
|
||||
// });
|
||||
// });
|
||||
|
||||
postgresConnectionStrings['getConnectionStrings']().forEach(k => {
|
||||
should(k.value.includes(endpoint[0])).be.True();
|
||||
should(k.value.includes(endpoint[1])).be.True();
|
||||
});
|
||||
});
|
||||
// });
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
@@ -1,110 +1,109 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// /*---------------------------------------------------------------------------------------------
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// * Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
// *--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as sinon from 'sinon';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as utils from '../../../common/utils';
|
||||
import * as loc from '../../../localizedConstants';
|
||||
import { Deferred } from '../../../common/promise';
|
||||
import { createModelViewMock } from '@microsoft/azdata-test/out/mocks/modelView/modelViewMock';
|
||||
import { StubButton } from '@microsoft/azdata-test/out/stubs/modelView/stubButton';
|
||||
import { PGResourceInfo, ResourceType } from 'arc';
|
||||
import { PostgresOverviewPage } from '../../../ui/dashboards/postgres/postgresOverviewPage';
|
||||
import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
import { FakeAzdataApi } from '../../mocks/fakeAzdataApi';
|
||||
import { PostgresModel } from '../../../models/postgresModel';
|
||||
import { ControllerModel, Registration } from '../../../models/controllerModel';
|
||||
// import * as vscode from 'vscode';
|
||||
// import * as sinon from 'sinon';
|
||||
// import * as TypeMoq from 'typemoq';
|
||||
// import * as azExt from 'azdata-ext';
|
||||
// import * as utils from '../../../common/utils';
|
||||
// import * as loc from '../../../localizedConstants';
|
||||
// import { Deferred } from '../../../common/promise';
|
||||
// import { createModelViewMock } from '@microsoft/azdata-test/out/mocks/modelView/modelViewMock';
|
||||
// import { StubButton } from '@microsoft/azdata-test/out/stubs/modelView/stubButton';
|
||||
// import { PGResourceInfo, ResourceType } from 'arc';
|
||||
// import { PostgresOverviewPage } from '../../../ui/dashboards/postgres/postgresOverviewPage';
|
||||
// import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
// import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
// import { FakeAzApi } from '../../mocks/fakeAzdataApi';
|
||||
// import { PostgresModel } from '../../../models/postgresModel';
|
||||
// import { ControllerModel, Registration } from '../../../models/controllerModel';
|
||||
|
||||
describe('postgresOverviewPage', () => {
|
||||
let postgresOverview: PostgresOverviewPage;
|
||||
let azdataApi: azdataExt.IAzdataApi;
|
||||
let controllerModel: ControllerModel;
|
||||
let postgresModel: PostgresModel;
|
||||
// describe('postgresOverviewPage', () => {
|
||||
// let postgresOverview: PostgresOverviewPage;
|
||||
// let azdataApi: azExt.IAzdataApi;
|
||||
// let controllerModel: ControllerModel;
|
||||
// let postgresModel: PostgresModel;
|
||||
|
||||
let showInformationMessage: sinon.SinonStub;
|
||||
let showErrorMessage: sinon.SinonStub;
|
||||
// let showInformationMessage: sinon.SinonStub;
|
||||
// let showErrorMessage: sinon.SinonStub;
|
||||
|
||||
let informationMessageShown: Deferred;
|
||||
let errorMessageShown: Deferred;
|
||||
// let informationMessageShown: Deferred;
|
||||
// let errorMessageShown: Deferred;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Stub the azdata CLI API
|
||||
azdataApi = new FakeAzdataApi();
|
||||
const azdataExt = TypeMoq.Mock.ofType<azdataExt.IExtension>();
|
||||
azdataExt.setup(x => x.azdata).returns(() => azdataApi);
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: azdataExt.object });
|
||||
// beforeEach(async () => {
|
||||
// // Stub the azdata CLI API
|
||||
// azdataApi = new FakeAzdataApi();
|
||||
// const azExt = TypeMoq.Mock.ofType<azExt.IExtension>();
|
||||
// azExt.setup(x => x.azdata).returns(() => azdataApi);
|
||||
// sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: azExt.object });
|
||||
|
||||
// Stub the window UI
|
||||
informationMessageShown = new Deferred();
|
||||
showInformationMessage = sinon.stub(vscode.window, 'showInformationMessage').callsFake(
|
||||
(_: string, __: vscode.MessageOptions, ...___: vscode.MessageItem[]) => {
|
||||
informationMessageShown.resolve();
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
// // Stub the window UI
|
||||
// informationMessageShown = new Deferred();
|
||||
// showInformationMessage = sinon.stub(vscode.window, 'showInformationMessage').callsFake(
|
||||
// (_: string, __: vscode.MessageOptions, ...___: vscode.MessageItem[]) => {
|
||||
// informationMessageShown.resolve();
|
||||
// return Promise.resolve(undefined);
|
||||
// });
|
||||
|
||||
errorMessageShown = new Deferred();
|
||||
showErrorMessage = sinon.stub(vscode.window, 'showErrorMessage').callsFake(
|
||||
(_: string, __: vscode.MessageOptions, ...___: vscode.MessageItem[]) => {
|
||||
errorMessageShown.resolve();
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
// errorMessageShown = new Deferred();
|
||||
// showErrorMessage = sinon.stub(vscode.window, 'showErrorMessage').callsFake(
|
||||
// (_: string, __: vscode.MessageOptions, ...___: vscode.MessageItem[]) => {
|
||||
// errorMessageShown.resolve();
|
||||
// return Promise.resolve(undefined);
|
||||
// });
|
||||
|
||||
// Setup the PostgresModel
|
||||
controllerModel = new FakeControllerModel();
|
||||
const postgresResource: PGResourceInfo = { name: 'my-pg', resourceType: '' };
|
||||
const registration: Registration = { instanceName: '', state: '', instanceType: ResourceType.postgresInstances };
|
||||
const treeDataProvider = new AzureArcTreeDataProvider(TypeMoq.Mock.ofType<vscode.ExtensionContext>().object);
|
||||
postgresModel = new PostgresModel(controllerModel, postgresResource, registration, treeDataProvider);
|
||||
// // Setup the PostgresModel
|
||||
// controllerModel = new FakeControllerModel();
|
||||
// const postgresResource: PGResourceInfo = { name: 'my-pg', resourceType: '' };
|
||||
// const registration: Registration = { instanceName: '', state: '', instanceType: ResourceType.postgresInstances };
|
||||
// const treeDataProvider = new AzureArcTreeDataProvider(TypeMoq.Mock.ofType<vscode.ExtensionContext>().object);
|
||||
// postgresModel = new PostgresModel(controllerModel, postgresResource, registration, treeDataProvider);
|
||||
|
||||
// Setup the PostgresOverviewPage
|
||||
const { modelViewMock } = createModelViewMock();
|
||||
postgresOverview = new PostgresOverviewPage(modelViewMock.object, undefined!, controllerModel, postgresModel);
|
||||
// Call the getter to initialize toolbar, but we don't need to use it for anything
|
||||
// eslint-disable-next-line code-no-unused-expressions
|
||||
postgresOverview['toolbarContainer'];
|
||||
});
|
||||
// // Setup the PostgresOverviewPage
|
||||
// const { modelViewMock } = createModelViewMock();
|
||||
// postgresOverview = new PostgresOverviewPage(modelViewMock.object, undefined!, controllerModel, postgresModel);
|
||||
// // Call the getter to initialize toolbar, but we don't need to use it for anything
|
||||
// // eslint-disable-next-line code-no-unused-expressions
|
||||
// postgresOverview['toolbarContainer'];
|
||||
// });
|
||||
|
||||
afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
// afterEach(() => {
|
||||
// sinon.restore();
|
||||
// });
|
||||
|
||||
describe('delete button', () => {
|
||||
let refreshTreeNode: sinon.SinonStub;
|
||||
// describe('delete button', () => {
|
||||
// let refreshTreeNode: sinon.SinonStub;
|
||||
|
||||
beforeEach(() => {
|
||||
sinon.stub(utils, 'promptForInstanceDeletion').returns(Promise.resolve(true));
|
||||
sinon.stub(controllerModel, 'login').returns(Promise.resolve());
|
||||
refreshTreeNode = sinon.stub(controllerModel, 'refreshTreeNode');
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// sinon.stub(utils, 'promptForInstanceDeletion').returns(Promise.resolve(true));
|
||||
// refreshTreeNode = sinon.stub(controllerModel, 'refreshTreeNode');
|
||||
// });
|
||||
|
||||
it('deletes Postgres on success', async () => {
|
||||
// Stub 'azdata arc postgres server delete' to return success
|
||||
const postgresDeleteStub = sinon.stub(azdataApi.arc.postgres.server, 'delete');
|
||||
// it('deletes Postgres on success', async () => {
|
||||
// // Stub 'azdata arc postgres server delete' to return success
|
||||
// const postgresDeleteStub = sinon.stub(azdataApi.arc.postgres.server, 'delete');
|
||||
|
||||
(postgresOverview['deleteButton'] as StubButton).click();
|
||||
await informationMessageShown;
|
||||
sinon.assert.calledOnceWithExactly(postgresDeleteStub, postgresModel.info.name, sinon.match.any, sinon.match.any);
|
||||
sinon.assert.calledOnceWithExactly(showInformationMessage, loc.instanceDeleted(postgresModel.info.name));
|
||||
sinon.assert.notCalled(showErrorMessage);
|
||||
sinon.assert.calledOnce(refreshTreeNode);
|
||||
});
|
||||
// (postgresOverview['deleteButton'] as StubButton).click();
|
||||
// await informationMessageShown;
|
||||
// sinon.assert.calledOnceWithExactly(postgresDeleteStub, postgresModel.info.name, sinon.match.any, sinon.match.any);
|
||||
// sinon.assert.calledOnceWithExactly(showInformationMessage, loc.instanceDeleted(postgresModel.info.name));
|
||||
// sinon.assert.notCalled(showErrorMessage);
|
||||
// sinon.assert.calledOnce(refreshTreeNode);
|
||||
// });
|
||||
|
||||
it('shows an error message on failure', async () => {
|
||||
// Stub 'azdata arc postgres server delete' to throw an exception
|
||||
const error = new Error('something bad happened');
|
||||
const postgresDeleteStub = sinon.stub(azdataApi.arc.postgres.server, 'delete').throws(error);
|
||||
// it('shows an error message on failure', async () => {
|
||||
// // Stub 'azdata arc postgres server delete' to throw an exception
|
||||
// const error = new Error('something bad happened');
|
||||
// const postgresDeleteStub = sinon.stub(azdataApi.arc.postgres.server, 'delete').throws(error);
|
||||
|
||||
(postgresOverview['deleteButton'] as StubButton).click();
|
||||
await errorMessageShown;
|
||||
sinon.assert.calledOnceWithExactly(postgresDeleteStub, postgresModel.info.name, sinon.match.any, sinon.match.any);
|
||||
sinon.assert.notCalled(showInformationMessage);
|
||||
sinon.assert.calledOnceWithExactly(showErrorMessage, loc.instanceDeletionFailed(postgresModel.info.name, error.message));
|
||||
sinon.assert.notCalled(refreshTreeNode);
|
||||
});
|
||||
});
|
||||
});
|
||||
// (postgresOverview['deleteButton'] as StubButton).click();
|
||||
// await errorMessageShown;
|
||||
// sinon.assert.calledOnceWithExactly(postgresDeleteStub, postgresModel.info.name, sinon.match.any, sinon.match.any);
|
||||
// sinon.assert.notCalled(showInformationMessage);
|
||||
// sinon.assert.calledOnceWithExactly(showErrorMessage, loc.instanceDeletionFailed(postgresModel.info.name, error.message));
|
||||
// sinon.assert.notCalled(refreshTreeNode);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// /*---------------------------------------------------------------------------------------------
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// * Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
// *--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ControllerInfo } from 'arc';
|
||||
import * as should from 'should';
|
||||
import * as sinon from 'sinon';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as loc from '../../../localizedConstants';
|
||||
import { ControllerModel } from '../../../models/controllerModel';
|
||||
import { ConnectToControllerDialog } from '../../../ui/dialogs/connectControllerDialog';
|
||||
// import { ControllerInfo } from 'arc';
|
||||
// import * as should from 'should';
|
||||
// import * as sinon from 'sinon';
|
||||
// import { v4 as uuid } from 'uuid';
|
||||
// import * as loc from '../../../localizedConstants';
|
||||
// import { ControllerModel } from '../../../models/controllerModel';
|
||||
// import { ConnectToControllerDialog } from '../../../ui/dialogs/connectControllerDialog';
|
||||
|
||||
describe('ConnectControllerDialog', function (): void {
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
// describe('ConnectControllerDialog', function (): void {
|
||||
// afterEach(function (): void {
|
||||
// sinon.restore();
|
||||
// });
|
||||
|
||||
(<{ info: ControllerInfo | undefined, description: string }[]>[
|
||||
{ info: undefined, description: 'all input' },
|
||||
{ info: { endpoint: '127.0.0.1' }, description: 'all but URL' },
|
||||
{ info: { endpoint: '127.0.0.1', username: 'sa' }, description: 'all but URL and password' }]).forEach(test => {
|
||||
it(`Validate returns false when ${test.description} is empty`, async function (): Promise<void> {
|
||||
const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
connectControllerDialog.showDialog(test.info, undefined);
|
||||
await connectControllerDialog.isInitialized;
|
||||
const validateResult = await connectControllerDialog.validate();
|
||||
should(validateResult).be.false();
|
||||
});
|
||||
});
|
||||
// (<{ info: ControllerInfo | undefined, description: string }[]>[
|
||||
// { info: undefined, description: 'all input' },
|
||||
// { info: { endpoint: '127.0.0.1' }, description: 'all but URL' },
|
||||
// { info: { endpoint: '127.0.0.1', username: 'sa' }, description: 'all but URL and password' }]).forEach(test => {
|
||||
// it(`Validate returns false when ${test.description} is empty`, async function (): Promise<void> {
|
||||
// const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
// connectControllerDialog.showDialog(test.info, undefined);
|
||||
// await connectControllerDialog.isInitialized;
|
||||
// const validateResult = await connectControllerDialog.validate();
|
||||
// should(validateResult).be.false();
|
||||
// });
|
||||
// });
|
||||
|
||||
it('validate returns false if controller refresh fails', async function (): Promise<void> {
|
||||
sinon.stub(ControllerModel.prototype, 'refresh').returns(Promise.reject('Controller refresh failed'));
|
||||
const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
const info: ControllerInfo = { id: uuid(), endpoint: 'https://127.0.0.1:30080', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] };
|
||||
connectControllerDialog.showDialog(info, 'pwd');
|
||||
await connectControllerDialog.isInitialized;
|
||||
const validateResult = await connectControllerDialog.validate();
|
||||
should(validateResult).be.false('Validation should have returned false');
|
||||
});
|
||||
// it('validate returns false if controller refresh fails', async function (): Promise<void> {
|
||||
// sinon.stub(ControllerModel.prototype, 'refresh').returns(Promise.reject('Controller refresh failed'));
|
||||
// const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
// const info: ControllerInfo = { id: uuid(), endpoint: 'https://127.0.0.1:30080', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] };
|
||||
// connectControllerDialog.showDialog(info, 'pwd');
|
||||
// await connectControllerDialog.isInitialized;
|
||||
// const validateResult = await connectControllerDialog.validate();
|
||||
// should(validateResult).be.false('Validation should have returned false');
|
||||
// });
|
||||
|
||||
it('validate replaces http with https', async function (): Promise<void> {
|
||||
await validateConnectControllerDialog(
|
||||
{ id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30081');
|
||||
});
|
||||
// it('validate replaces http with https', async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog(
|
||||
// { id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30081');
|
||||
// });
|
||||
|
||||
it('validate appends https if missing', async function (): Promise<void> {
|
||||
await validateConnectControllerDialog({ id: uuid(), endpoint: '127.0.0.1:30080', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30080');
|
||||
});
|
||||
// it('validate appends https if missing', async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog({ id: uuid(), endpoint: '127.0.0.1:30080', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30080');
|
||||
// });
|
||||
|
||||
it('validate appends default port if missing', async function (): Promise<void> {
|
||||
await validateConnectControllerDialog({ id: uuid(), endpoint: 'https://127.0.0.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30080');
|
||||
});
|
||||
// it('validate appends default port if missing', async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog({ id: uuid(), endpoint: 'https://127.0.0.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30080');
|
||||
// });
|
||||
|
||||
it('validate appends both port and https if missing', async function (): Promise<void> {
|
||||
await validateConnectControllerDialog({ id: uuid(), endpoint: '127.0.0.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30080');
|
||||
});
|
||||
// it('validate appends both port and https if missing', async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog({ id: uuid(), endpoint: '127.0.0.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'my-arc', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30080');
|
||||
// });
|
||||
|
||||
for (const name of ['', undefined]) {
|
||||
it.skip(`validate display name gets set to arc instance name for user chosen name of:${name}`, async function (): Promise<void> {
|
||||
await validateConnectControllerDialog(
|
||||
{ id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: name!, namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30081');
|
||||
});
|
||||
}
|
||||
// for (const name of ['', undefined]) {
|
||||
// it.skip(`validate display name gets set to arc instance name for user chosen name of:${name}`, async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog(
|
||||
// { id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: name!, namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30081');
|
||||
// });
|
||||
// }
|
||||
|
||||
it.skip(`validate display name gets set to default data controller name for user chosen name of:'' and instanceName in explicably returned as undefined from the controller endpoint`, async function (): Promise<void> {
|
||||
await validateConnectControllerDialog(
|
||||
{ id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: '', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
'https://127.0.0.1:30081',
|
||||
undefined);
|
||||
});
|
||||
});
|
||||
// it.skip(`validate display name gets set to default data controller name for user chosen name of:'' and instanceName in explicably returned as undefined from the controller endpoint`, async function (): Promise<void> {
|
||||
// await validateConnectControllerDialog(
|
||||
// { id: uuid(), endpoint: 'http://127.0.0.1:30081', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: '', namespace: 'arc-ns', username: 'sa', rememberPassword: true, resources: [] },
|
||||
// 'https://127.0.0.1:30081',
|
||||
// undefined);
|
||||
// });
|
||||
// });
|
||||
|
||||
async function validateConnectControllerDialog(info: ControllerInfo, expectedUrl: string, arcInstanceName: string = 'arc-instance'): Promise<void> {
|
||||
const expectedControllerInfoName = info.name || arcInstanceName || loc.defaultControllerName;
|
||||
const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
// Stub out refresh calls to controllerModel - we'll test those separately
|
||||
sinon.stub(ControllerModel.prototype, 'refresh').returns(Promise.resolve());
|
||||
// stub out controller registration response to return a known instanceName for the dc.
|
||||
/*
|
||||
sinon.stub(ControllerModel.prototype, 'controllerRegistration').get(() => {
|
||||
return <Registration>{ instanceName: arcInstanceName };
|
||||
});
|
||||
*/
|
||||
connectControllerDialog.showDialog(info, 'pwd');
|
||||
await connectControllerDialog.isInitialized;
|
||||
const validateResult = await connectControllerDialog.validate();
|
||||
should(validateResult).be.true('Validation should have returned true');
|
||||
const model = await connectControllerDialog.waitForClose();
|
||||
should(model?.controllerModel.info.endpoint).equal(expectedUrl);
|
||||
should(model?.controllerModel.info.name).equal(expectedControllerInfoName);
|
||||
}
|
||||
// async function validateConnectControllerDialog(info: ControllerInfo, expectedUrl: string, arcInstanceName: string = 'arc-instance'): Promise<void> {
|
||||
// const expectedControllerInfoName = info.name || arcInstanceName || loc.defaultControllerName;
|
||||
// const connectControllerDialog = new ConnectToControllerDialog(undefined!);
|
||||
// // Stub out refresh calls to controllerModel - we'll test those separately
|
||||
// sinon.stub(ControllerModel.prototype, 'refresh').returns(Promise.resolve());
|
||||
// // stub out controller registration response to return a known instanceName for the dc.
|
||||
// /*
|
||||
// sinon.stub(ControllerModel.prototype, 'controllerRegistration').get(() => {
|
||||
// return <Registration>{ instanceName: arcInstanceName };
|
||||
// });
|
||||
// */
|
||||
// connectControllerDialog.showDialog(info, 'pwd');
|
||||
// await connectControllerDialog.isInitialized;
|
||||
// const validateResult = await connectControllerDialog.validate();
|
||||
// should(validateResult).be.true('Validation should have returned true');
|
||||
// const model = await connectControllerDialog.waitForClose();
|
||||
// should(model?.controllerModel.info.endpoint).equal(expectedUrl);
|
||||
// should(model?.controllerModel.info.name).equal(expectedControllerInfoName);
|
||||
// }
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// /*---------------------------------------------------------------------------------------------
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// * Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
// *--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ControllerInfo, ResourceType } from 'arc';
|
||||
import 'mocha';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as kubeUtils from '../../../common/kubeUtils';
|
||||
import { ControllerModel } from '../../../models/controllerModel';
|
||||
import { MiaaModel } from '../../../models/miaaModel';
|
||||
import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
import { ControllerTreeNode } from '../../../ui/tree/controllerTreeNode';
|
||||
import { MiaaTreeNode } from '../../../ui/tree/miaaTreeNode';
|
||||
import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
import { FakeAzdataApi } from '../../mocks/fakeAzdataApi';
|
||||
// import { ControllerInfo, ResourceType } from 'arc';
|
||||
// import 'mocha';
|
||||
// import * as should from 'should';
|
||||
// import * as TypeMoq from 'typemoq';
|
||||
// import * as sinon from 'sinon';
|
||||
// import { v4 as uuid } from 'uuid';
|
||||
// import * as vscode from 'vscode';
|
||||
// import * as azdataExt from 'azdata-ext';
|
||||
// import * as kubeUtils from '../../../common/kubeUtils';
|
||||
// import { ControllerModel } from '../../../models/controllerModel';
|
||||
// import { MiaaModel } from '../../../models/miaaModel';
|
||||
// import { AzureArcTreeDataProvider } from '../../../ui/tree/azureArcTreeDataProvider';
|
||||
// import { ControllerTreeNode } from '../../../ui/tree/controllerTreeNode';
|
||||
// import { MiaaTreeNode } from '../../../ui/tree/miaaTreeNode';
|
||||
// import { FakeControllerModel } from '../../mocks/fakeControllerModel';
|
||||
// import { FakeAzdataApi } from '../../mocks/fakeAzdataApi';
|
||||
|
||||
interface ExtensionGlobalMemento extends vscode.Memento {
|
||||
setKeysForSync(keys: string[]): void;
|
||||
}
|
||||
// interface ExtensionGlobalMemento extends vscode.Memento {
|
||||
// setKeysForSync(keys: string[]): void;
|
||||
// }
|
||||
|
||||
function getDefaultControllerInfo(): ControllerInfo {
|
||||
return {
|
||||
id: uuid(),
|
||||
endpoint: '127.0.0.1',
|
||||
kubeConfigFilePath: '/path/to/.kube/config',
|
||||
kubeClusterContext: 'currentCluster',
|
||||
username: 'sa',
|
||||
name: 'my-arc',
|
||||
namespace: 'arc-ns',
|
||||
rememberPassword: true,
|
||||
resources: []
|
||||
};
|
||||
}
|
||||
// function getDefaultControllerInfo(): ControllerInfo {
|
||||
// return {
|
||||
// id: uuid(),
|
||||
// endpoint: '127.0.0.1',
|
||||
// kubeConfigFilePath: '/path/to/.kube/config',
|
||||
// kubeClusterContext: 'currentCluster',
|
||||
// username: 'sa',
|
||||
// name: 'my-arc',
|
||||
// namespace: 'arc-ns',
|
||||
// rememberPassword: true,
|
||||
// resources: []
|
||||
// };
|
||||
// }
|
||||
|
||||
describe('AzureArcTreeDataProvider tests', function (): void {
|
||||
let treeDataProvider: AzureArcTreeDataProvider;
|
||||
beforeEach(function (): void {
|
||||
const mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
const mockGlobalState = TypeMoq.Mock.ofType<ExtensionGlobalMemento>();
|
||||
mockGlobalState.setup(x => x.update(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
mockExtensionContext.setup(x => x.globalState).returns(() => mockGlobalState.object);
|
||||
//treeDataProviderMock = TypeMoq.Mock.ofType<AzureArcTreeDataProvider>();
|
||||
treeDataProvider = new AzureArcTreeDataProvider(mockExtensionContext.object);
|
||||
});
|
||||
// describe('AzureArcTreeDataProvider tests', function (): void {
|
||||
// let treeDataProvider: AzureArcTreeDataProvider;
|
||||
// beforeEach(function (): void {
|
||||
// const mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
// const mockGlobalState = TypeMoq.Mock.ofType<ExtensionGlobalMemento>();
|
||||
// mockGlobalState.setup(x => x.update(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
// mockExtensionContext.setup(x => x.globalState).returns(() => mockGlobalState.object);
|
||||
// //treeDataProviderMock = TypeMoq.Mock.ofType<AzureArcTreeDataProvider>();
|
||||
// treeDataProvider = new AzureArcTreeDataProvider(mockExtensionContext.object);
|
||||
// });
|
||||
|
||||
describe('addOrUpdateController', function (): void {
|
||||
it('Multiple Controllers are added correctly', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = false;
|
||||
let children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
const controllerModel = new FakeControllerModel();
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
// describe('addOrUpdateController', function (): void {
|
||||
// it('Multiple Controllers are added correctly', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = false;
|
||||
// let children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
// const controllerModel = new FakeControllerModel();
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
|
||||
// Add a couple more
|
||||
const controllerModel2 = new FakeControllerModel();
|
||||
const controllerModel3 = new FakeControllerModel();
|
||||
await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
await treeDataProvider.addOrUpdateController(controllerModel3, '');
|
||||
children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(3, 'Additional Controller nodes should be added correctly');
|
||||
});
|
||||
// // Add a couple more
|
||||
// const controllerModel2 = new FakeControllerModel();
|
||||
// const controllerModel3 = new FakeControllerModel();
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel3, '');
|
||||
// children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(3, 'Additional Controller nodes should be added correctly');
|
||||
// });
|
||||
|
||||
it('Adding a Controller more than once doesn\'t create duplicates', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = false;
|
||||
let children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
|
||||
});
|
||||
// it('Adding a Controller more than once doesn\'t create duplicates', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = false;
|
||||
// let children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
|
||||
// });
|
||||
|
||||
it('Updating an existing controller works as expected', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = false;
|
||||
let children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
const originalInfo: ControllerInfo = getDefaultControllerInfo();
|
||||
const controllerModel = new ControllerModel(treeDataProvider, originalInfo);
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
should((<ControllerTreeNode>children[0]).model.info).deepEqual(originalInfo);
|
||||
const newInfo: ControllerInfo = { id: originalInfo.id, endpoint: '1.1.1.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'new-name', namespace: 'new-namespace', username: 'admin', rememberPassword: false, resources: [] };
|
||||
const controllerModel2 = new ControllerModel(treeDataProvider, newInfo);
|
||||
await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
|
||||
should((<ControllerTreeNode>children[0]).model.info).deepEqual(newInfo);
|
||||
});
|
||||
});
|
||||
// it('Updating an existing controller works as expected', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = false;
|
||||
// let children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(0, 'There initially shouldn\'t be any children');
|
||||
// const originalInfo: ControllerInfo = getDefaultControllerInfo();
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, originalInfo);
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// should(children.length).equal(1, 'Controller node should be added correctly');
|
||||
// should((<ControllerTreeNode>children[0]).model.info).deepEqual(originalInfo);
|
||||
// const newInfo: ControllerInfo = { id: originalInfo.id, endpoint: '1.1.1.1', kubeConfigFilePath: '/path/to/.kube/config', kubeClusterContext: 'currentCluster', name: 'new-name', namespace: 'new-namespace', username: 'admin', rememberPassword: false, resources: [] };
|
||||
// const controllerModel2 = new ControllerModel(treeDataProvider, newInfo);
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
// should(children.length).equal(1, 'Shouldn\'t add duplicate controller node');
|
||||
// should((<ControllerTreeNode>children[0]).model.info).deepEqual(newInfo);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('getChildren', function (): void {
|
||||
it('should return an empty array before loading stored controllers is completed', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = true;
|
||||
let children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(0, 'While loading we should return an empty array');
|
||||
});
|
||||
// describe('getChildren', function (): void {
|
||||
// it('should return an empty array before loading stored controllers is completed', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = true;
|
||||
// let children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(0, 'While loading we should return an empty array');
|
||||
// });
|
||||
|
||||
it('should return no children after loading', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = false;
|
||||
let children = await treeDataProvider.getChildren();
|
||||
should(children.length).equal(0, 'After loading we should have 0 children');
|
||||
});
|
||||
// it('should return no children after loading', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = false;
|
||||
// let children = await treeDataProvider.getChildren();
|
||||
// should(children.length).equal(0, 'After loading we should have 0 children');
|
||||
// });
|
||||
|
||||
it('should return all children of controller after loading', async function (): Promise<void> {
|
||||
const mockArcExtension = TypeMoq.Mock.ofType<vscode.Extension<any>>();
|
||||
const mockArcApi = TypeMoq.Mock.ofType<azdataExt.IExtension>();
|
||||
mockArcExtension.setup(x => x.exports).returns(() => {
|
||||
return mockArcApi.object;
|
||||
});
|
||||
const fakeAzdataApi = new FakeAzdataApi();
|
||||
const pgInstances = [{ name: 'pg1', state: '', workers: 0 }];
|
||||
const miaaInstances = [{ name: 'miaa1', state: '', replicas: '', serverEndpoint: '' }];
|
||||
fakeAzdataApi.postgresInstances = pgInstances;
|
||||
fakeAzdataApi.miaaInstances = miaaInstances;
|
||||
mockArcApi.setup(x => x.azdata).returns(() => fakeAzdataApi);
|
||||
// it('should return all children of controller after loading', async function (): Promise<void> {
|
||||
// const mockArcExtension = TypeMoq.Mock.ofType<vscode.Extension<any>>();
|
||||
// const mockArcApi = TypeMoq.Mock.ofType<azdataExt.IExtension>();
|
||||
// mockArcExtension.setup(x => x.exports).returns(() => {
|
||||
// return mockArcApi.object;
|
||||
// });
|
||||
// const fakeAzdataApi = new FakeAzdataApi();
|
||||
// const pgInstances = [{ name: 'pg1', state: '', workers: 0 }];
|
||||
// const miaaInstances = [{ name: 'miaa1', state: '', replicas: '', serverEndpoint: '' }];
|
||||
// fakeAzdataApi.postgresInstances = pgInstances;
|
||||
// fakeAzdataApi.miaaInstances = miaaInstances;
|
||||
// mockArcApi.setup(x => x.azdata).returns(() => fakeAzdataApi);
|
||||
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(mockArcExtension.object);
|
||||
sinon.stub(kubeUtils, 'getKubeConfigClusterContexts').returns([{ name: 'currentCluster', isCurrentContext: true }]);
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo(), 'mypassword');
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
const controllerNode = treeDataProvider.getControllerNode(controllerModel);
|
||||
const children = await treeDataProvider.getChildren(controllerNode);
|
||||
should(children.filter(c => c.label === pgInstances[0].name).length).equal(1, 'Should have a Postgres child');
|
||||
should(children.filter(c => c.label === miaaInstances[0].name).length).equal(1, 'Should have a MIAA child');
|
||||
should(children.length).equal(2, 'Should have exactly 2 children');
|
||||
});
|
||||
});
|
||||
// sinon.stub(vscode.extensions, 'getExtension').returns(mockArcExtension.object);
|
||||
// sinon.stub(kubeUtils, 'getKubeConfigClusterContexts').returns([{ name: 'currentCluster', isCurrentContext: true }]);
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo(), 'mypassword');
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// const controllerNode = treeDataProvider.getControllerNode(controllerModel);
|
||||
// const children = await treeDataProvider.getChildren(controllerNode);
|
||||
// should(children.filter(c => c.label === pgInstances[0].name).length).equal(1, 'Should have a Postgres child');
|
||||
// should(children.filter(c => c.label === miaaInstances[0].name).length).equal(1, 'Should have a MIAA child');
|
||||
// should(children.length).equal(2, 'Should have exactly 2 children');
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('removeController', function (): void {
|
||||
it('removing a controller should work as expected', async function (): Promise<void> {
|
||||
treeDataProvider['_loading'] = false;
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
const info2 = getDefaultControllerInfo();
|
||||
info2.username = 'cloudsa';
|
||||
const controllerModel2 = new ControllerModel(treeDataProvider, info2);
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
const children = <ControllerTreeNode[]>(await treeDataProvider.getChildren());
|
||||
await treeDataProvider.removeController(children[0]);
|
||||
should((await treeDataProvider.getChildren()).length).equal(1, 'Node should have been removed');
|
||||
await treeDataProvider.removeController(children[0]);
|
||||
should((await treeDataProvider.getChildren()).length).equal(1, 'Removing same node again should do nothing');
|
||||
await treeDataProvider.removeController(children[1]);
|
||||
should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node should work');
|
||||
await treeDataProvider.removeController(children[1]);
|
||||
should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node again should do nothing');
|
||||
});
|
||||
});
|
||||
// describe('removeController', function (): void {
|
||||
// it('removing a controller should work as expected', async function (): Promise<void> {
|
||||
// treeDataProvider['_loading'] = false;
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
// const info2 = getDefaultControllerInfo();
|
||||
// info2.username = 'cloudsa';
|
||||
// const controllerModel2 = new ControllerModel(treeDataProvider, info2);
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel2, '');
|
||||
// const children = <ControllerTreeNode[]>(await treeDataProvider.getChildren());
|
||||
// await treeDataProvider.removeController(children[0]);
|
||||
// should((await treeDataProvider.getChildren()).length).equal(1, 'Node should have been removed');
|
||||
// await treeDataProvider.removeController(children[0]);
|
||||
// should((await treeDataProvider.getChildren()).length).equal(1, 'Removing same node again should do nothing');
|
||||
// await treeDataProvider.removeController(children[1]);
|
||||
// should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node should work');
|
||||
// await treeDataProvider.removeController(children[1]);
|
||||
// should((await treeDataProvider.getChildren()).length).equal(0, 'Removing other node again should do nothing');
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('openResourceDashboard', function (): void {
|
||||
it('Opening dashboard for nonexistent controller node throws', async function (): Promise<void> {
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
const openDashboardPromise = treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
await should(openDashboardPromise).be.rejected();
|
||||
});
|
||||
// describe('openResourceDashboard', function (): void {
|
||||
// it('Opening dashboard for nonexistent controller node throws', async function (): Promise<void> {
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
// const openDashboardPromise = treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
// await should(openDashboardPromise).be.rejected();
|
||||
// });
|
||||
|
||||
it('Opening dashboard for nonexistent resource throws', async function (): Promise<void> {
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
const openDashboardPromise = treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
await should(openDashboardPromise).be.rejected();
|
||||
});
|
||||
// it('Opening dashboard for nonexistent resource throws', async function (): Promise<void> {
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// const openDashboardPromise = treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
// await should(openDashboardPromise).be.rejected();
|
||||
// });
|
||||
|
||||
it('Opening dashboard for existing resource node succeeds', async function (): Promise<void> {
|
||||
const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
const miaaModel = new MiaaModel(controllerModel, { name: 'miaa-1', resourceType: ResourceType.sqlManagedInstances }, undefined!, treeDataProvider);
|
||||
await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
const controllerNode = treeDataProvider.getControllerNode(controllerModel)!;
|
||||
const resourceNode = new MiaaTreeNode(miaaModel, controllerModel);
|
||||
sinon.stub(controllerNode, 'getResourceNode').returns(resourceNode);
|
||||
const showDashboardStub = sinon.stub(resourceNode, 'openDashboard');
|
||||
await treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
should(showDashboardStub.calledOnce).be.true('showDashboard should have been called exactly once');
|
||||
});
|
||||
});
|
||||
});
|
||||
// it('Opening dashboard for existing resource node succeeds', async function (): Promise<void> {
|
||||
// const controllerModel = new ControllerModel(treeDataProvider, getDefaultControllerInfo());
|
||||
// const miaaModel = new MiaaModel(controllerModel, { name: 'miaa-1', resourceType: ResourceType.sqlManagedInstances }, undefined!, treeDataProvider);
|
||||
// await treeDataProvider.addOrUpdateController(controllerModel, '');
|
||||
// const controllerNode = treeDataProvider.getControllerNode(controllerModel)!;
|
||||
// const resourceNode = new MiaaTreeNode(miaaModel, controllerModel);
|
||||
// sinon.stub(controllerNode, 'getResourceNode').returns(resourceNode);
|
||||
// const showDashboardStub = sinon.stub(resourceNode, 'openDashboard');
|
||||
// await treeDataProvider.openResourceDashboard(controllerModel, ResourceType.sqlManagedInstances, '');
|
||||
// should(showDashboardStub.calledOnce).be.true('showDashboard should have been called exactly once');
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user