-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
datasource.ts
64 lines (56 loc) · 2.34 KB
/
datasource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Datasource from '../datasource';
type DeepPartial<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
};
export default function createMockDatasource(overrides?: DeepPartial<Datasource>) {
// We make this a partial so we get _some_ kind of type safety when making this, rather than
// having it be any or casted immediately to Datasource
const _mockDatasource: DeepPartial<Datasource> = {
getVariables: jest.fn().mockReturnValue([]),
azureMonitorDatasource: {
isConfigured() {
return true;
},
getSubscriptions: jest.fn().mockResolvedValueOnce([]),
defaultSubscriptionId: 'subscriptionId',
getMetricNamespaces: jest.fn().mockResolvedValueOnce([]),
getMetricNames: jest.fn().mockResolvedValueOnce([]),
getMetricMetadata: jest.fn().mockResolvedValueOnce({
primaryAggType: 'Average',
supportedAggTypes: ['Average', 'Maximum', 'Minimum'],
supportedTimeGrains: [],
dimensions: [],
}),
getProvider: jest.fn().mockResolvedValueOnce({
namespace: 'Microsoft.Insights',
resourceTypes: [
{ resourceType: 'logs', locations: ['North Europe'], apiVersions: ['2022-11-11'], capabilities: '' },
],
}),
getLocations: jest
.fn()
.mockResolvedValueOnce(
new Map([['northeurope', { displayName: 'North Europe', name: 'northeurope', supportsLogs: false }]])
),
},
getAzureLogAnalyticsWorkspaces: jest.fn().mockResolvedValueOnce([]),
getSubscriptions: jest.fn().mockResolvedValue([]),
getResourceGroups: jest.fn().mockResolvedValueOnce([]),
getResourceNames: jest.fn().mockResolvedValueOnce([]),
azureLogAnalyticsDatasource: {
getKustoSchema: () => Promise.resolve(),
getDeprecatedDefaultWorkSpace: () => 'defaultWorkspaceId',
},
resourcePickerData: {
getSubscriptions: () => jest.fn().mockResolvedValue([]),
getResourceGroupsBySubscriptionId: jest.fn().mockResolvedValue([]),
getResourcesForResourceGroup: jest.fn().mockResolvedValue([]),
getResourceURIFromWorkspace: jest.fn().mockReturnValue(''),
getResourceURIDisplayProperties: jest.fn().mockResolvedValue({}),
},
getVariablesRaw: jest.fn().mockReturnValue([]),
...overrides,
};
const mockDatasource = _mockDatasource as Datasource;
return jest.mocked(mockDatasource, true);
}