mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix deployment warnings to only show if no resources found (#10878)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as azurecore from '../../../azurecore/src/azurecore';
|
||||
|
||||
/**
|
||||
* Wrapper class to act as a facade over VSCode and Data APIs and allow us to test / mock callbacks into
|
||||
@@ -137,4 +138,16 @@ export class ApiWrapper {
|
||||
public registerWidget(widgetId: string, handler: (view: azdata.ModelView) => void): void {
|
||||
azdata.ui.registerModelViewProvider(widgetId, handler);
|
||||
}
|
||||
|
||||
private azurecoreApi: azurecore.IExtension | undefined;
|
||||
|
||||
public async getAzurecoreApi(): Promise<azurecore.IExtension> {
|
||||
if (!this.azurecoreApi) {
|
||||
this.azurecoreApi = await this.getExtension(azurecore.extension.name)?.activate();
|
||||
if (!this.azurecoreApi) {
|
||||
throw new Error('Unable to retrieve azurecore API');
|
||||
}
|
||||
}
|
||||
return this.azurecoreApi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export class AzureModelRegistryService {
|
||||
* @param account azure account
|
||||
*/
|
||||
public async getSubscriptions(account: azdata.Account | undefined): Promise<azureResource.AzureResourceSubscription[] | undefined> {
|
||||
const data = <azureResource.GetSubscriptionsResult>await this._apiWrapper.executeCommand(constants.azureSubscriptionsCommand, account, true);
|
||||
const data: azureResource.GetSubscriptionsResult = await (await this._apiWrapper.getAzurecoreApi()).getSubscriptions(account, true);
|
||||
return data?.subscriptions;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class AzureModelRegistryService {
|
||||
public async getGroups(
|
||||
account: azdata.Account | undefined,
|
||||
subscription: azureResource.AzureResourceSubscription | undefined): Promise<azureResource.AzureResource[] | undefined> {
|
||||
const data = <azureResource.GetResourceGroupsResult>await this._apiWrapper.executeCommand(constants.azureResourceGroupsCommand, account, subscription, true);
|
||||
const data: azureResource.GetResourceGroupsResult = await (await this._apiWrapper.getAzurecoreApi()).getResourceGroups(account, subscription, true);
|
||||
return data?.resourceGroups;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Workspace, WorkspacesListByResourceGroupResponse } from '@azure/arm-mac
|
||||
import { WorkspaceModel, AssetsQueryByIdResponse, Asset, GetArtifactContentInformation2Response } from '../../modelManagement/interfaces';
|
||||
import { AzureMachineLearningWorkspaces, Workspaces } from '@azure/arm-machinelearningservices';
|
||||
import { WorkspaceModels } from '../../modelManagement/workspacesModels';
|
||||
import { AzurecoreApiStub } from '../stubs';
|
||||
|
||||
interface TestContext {
|
||||
|
||||
@@ -129,7 +130,9 @@ describe('AzureModelRegistryService', () => {
|
||||
testContext.config.object,
|
||||
testContext.httpClient.object,
|
||||
testContext.outputChannel);
|
||||
testContext.apiWrapper.setup(x => x.executeCommand(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ subscriptions: expected, errors: [] }));
|
||||
const azurecoreApi = TypeMoq.Mock.ofType(AzurecoreApiStub);
|
||||
azurecoreApi.setup(x => x.getSubscriptions(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ subscriptions: expected, errors: [] }));
|
||||
testContext.apiWrapper.setup(x => x.getAzurecoreApi()).returns(() => Promise.resolve(azurecoreApi.object));
|
||||
let actual = await service.getSubscriptions(testContext.accounts[0]);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
@@ -142,7 +145,9 @@ describe('AzureModelRegistryService', () => {
|
||||
testContext.config.object,
|
||||
testContext.httpClient.object,
|
||||
testContext.outputChannel);
|
||||
testContext.apiWrapper.setup(x => x.executeCommand(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ resourceGroups: expected, errors: [] }));
|
||||
const azurecoreApi = TypeMoq.Mock.ofType(AzurecoreApiStub);
|
||||
azurecoreApi.setup(x => x.getResourceGroups(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ resourceGroups: expected, errors: [] }));
|
||||
testContext.apiWrapper.setup(x => x.getAzurecoreApi()).returns(() => Promise.resolve(azurecoreApi.object));
|
||||
let actual = await service.getGroups(testContext.accounts[0], testContext.subscriptions[0]);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
@@ -188,15 +193,15 @@ describe('AzureModelRegistryService', () => {
|
||||
it('downloadModel should download model artifact successfully', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
const asset: Asset =
|
||||
{
|
||||
id: '1',
|
||||
name: 'asset',
|
||||
artifacts: [
|
||||
{
|
||||
id: '/1/2/3/4/5/'
|
||||
}
|
||||
]
|
||||
};
|
||||
{
|
||||
id: '1',
|
||||
name: 'asset',
|
||||
artifacts: [
|
||||
{
|
||||
id: '/1/2/3/4/5/'
|
||||
}
|
||||
]
|
||||
};
|
||||
const assetResponse: AssetsQueryByIdResponse = Object.assign(asset, {
|
||||
_response: undefined!
|
||||
});
|
||||
|
||||
24
extensions/machine-learning/src/test/stubs.ts
Normal file
24
extensions/machine-learning/src/test/stubs.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as azurecore from '../../../azurecore/src/azurecore';
|
||||
import { azureResource } from '../../../azurecore/src/azureResource/azure-resource';
|
||||
|
||||
export class AzurecoreApiStub implements azurecore.IExtension {
|
||||
getSubscriptions(_account?: azdata.Account | undefined, _ignoreErrors?: boolean | undefined): Thenable<azurecore.GetSubscriptionsResult> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getResourceGroups(_account?: azdata.Account | undefined, _subscription?: azureResource.AzureResourceSubscription | undefined, _ignoreErrors?: boolean | undefined): Thenable<azurecore.GetResourceGroupsResult> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getRegionDisplayName(_region?: string | undefined): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
provideResources(): azureResource.IAzureResourceProvider[] {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user