Skip to content

Commit d55d3c8

Browse files
committed
Unrevert "Update to call List Supported Virtual Machine and Cloud Service SKUs (#2400)"
8a7424b Batch Service supports VM SKU API so reenabling service call.
1 parent c79ab61 commit d55d3c8

File tree

5 files changed

+293
-207
lines changed

5 files changed

+293
-207
lines changed

src/@batch-flask/ui/browse-layout/toggle-filter-button/toggle-filter-button.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("ToggleFilterButtonComponent", () => {
4848
});
4949
});
5050

51-
describe("when fitler is empty", () => {
51+
describe("when filter is empty", () => {
5252
it("should not show marker", () => {
5353
expect(de.query(By.css(".filtering"))).toBeFalsy();
5454
});

src/app/components/gallery/application-list/gallery-application-list.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("GalleryApplicationList", () => {
8888
expect(apps[3].query(By.css(".logo")).nativeElement.getAttribute("src")).toEqual(applications[2].icon);
8989
});
9090

91-
it("fitler", () => {
91+
it("filter", () => {
9292
testComponent.filter = "m";
9393
fixture.detectChanges();
9494

src/app/services/compute/vm-size.service.spec.ts

+44-84
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,20 @@ import { BehaviorSubject, of } from "rxjs";
33
import { take } from "rxjs/operators";
44
import { VmSizeService } from "./vm-size.service";
55
import {
6-
vmSizeSampleResponse as vmSizesResponse,
76
badResponseIsNaN,
8-
responseWithExtraCapability
7+
responseWithExtraCapability,
8+
virtualMachineResponse,
9+
cloudServiceResponse
910
} from "./vmsize_sample_responses";
1011

1112
const sub1 = new ArmSubscription({
1213
id: "/subscriptions/sub1",
1314
subscriptionId: "sub1",
1415
});
1516

16-
const githubDataResponse = {
17-
category: {
18-
all: [".*"],
19-
memory: [
20-
"^standard_d[0-9a-z]*$",
21-
],
22-
},
23-
all: [
24-
"^standard_d[0-9]*$",
25-
],
26-
paas: [
27-
"small",
28-
"medium",
29-
"large",
30-
"extralarge",
31-
],
32-
iaas: [
33-
"^standard_a[1-9][0-9]*$",
34-
],
35-
};
36-
3717
describe("VMSizeService", () => {
3818
let service: VmSizeService;
3919
let armSpy;
40-
let githubDataSpy;
4120
let accountServiceSpy;
4221

4322
const testWestusAccount = new ArmBatchAccount({
@@ -48,69 +27,66 @@ describe("VMSizeService", () => {
4827
subscription: sub1,
4928
});
5029

30+
const testBrazilAccount = new ArmBatchAccount({
31+
id: "/subs/sub-1/batchaccounts/acc-2",
32+
name: "acc-2",
33+
location: "brazilsouth",
34+
properties: {} as any,
35+
subscription: sub1,
36+
});
37+
38+
// westus account
39+
const westusCloudServiceQuery = `/subscriptions/${testWestusAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testWestusAccount.location}/cloudServiceSkus?api-version=2021-06-01`;
40+
const westusVMQuery = `/subscriptions/${testWestusAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testWestusAccount.location}/virtualMachineSkus?api-version=2021-06-01`;
41+
// brazilsouth account
42+
const brazilCloudServiceQuery = `/subscriptions/${testBrazilAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testBrazilAccount.location}/cloudServiceSkus?api-version=2021-06-01`
43+
const brazilVMQuery = `/subscriptions/${testBrazilAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testBrazilAccount.location}/virtualMachineSkus?api-version=2021-06-01`
44+
5145
beforeEach(() => {
5246
armSpy = {
53-
get: jasmine.createSpy("arm.get").and.returnValue(of(vmSizesResponse)),
54-
};
55-
56-
githubDataSpy = {
57-
get: jasmine.createSpy("githubData.get").and.returnValue(of(JSON.stringify(githubDataResponse))),
47+
get: jasmine.createSpy("arm.get")
48+
.withArgs(westusVMQuery).and.returnValue(of(virtualMachineResponse))
49+
.withArgs(westusCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
50+
.withArgs(brazilCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
51+
.withArgs(brazilVMQuery).and.returnValue(of(virtualMachineResponse))
5852
};
5953

6054
accountServiceSpy = {
6155
currentAccount: new BehaviorSubject(testWestusAccount),
6256
};
63-
service = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
57+
service = new VmSizeService(armSpy, accountServiceSpy);
6458
});
6559

6660
afterEach(() => {
6761
service.ngOnDestroy();
6862
});
6963

7064
it("use the batch account subscription and location for the sizes", async () => {
65+
expect(armSpy.get).toHaveBeenCalledTimes(0);
7166
await service.sizes.pipe(take(1)).toPromise();
72-
expect(armSpy.get).toHaveBeenCalledOnce();
73-
74-
const expectedOptionsParam = {
75-
params: {
76-
"$filter": `location eq '${testWestusAccount.location}'`
77-
}
78-
};
79-
80-
expect(armSpy.get).toHaveBeenCalledWith(
81-
"subscriptions/sub1/providers/Microsoft.Compute/skus", expectedOptionsParam);
67+
expect(armSpy.get).toHaveBeenCalledWith(westusVMQuery);
68+
expect(armSpy.get).toHaveBeenCalledWith(westusCloudServiceQuery);
8269
});
8370

8471
it("only calls the vm sizes api once per account", async () => {
8572
await service.sizes.pipe(take(1)).toPromise();
86-
expect(armSpy.get).toHaveBeenCalledOnce();
73+
expect(armSpy.get).toHaveBeenCalledTimes(2);
8774
await service.sizes.pipe(take(1)).toPromise();
88-
expect(armSpy.get).toHaveBeenCalledOnce();
75+
expect(armSpy.get).toHaveBeenCalledTimes(2);
8976
});
9077

9178
it("calls again when batch account changes", async () => {
92-
const sizeSub = service.sizes.subscribe();
93-
expect(armSpy.get).toHaveBeenCalledTimes(1);
94-
95-
const testBrazilAccount = new ArmBatchAccount({
96-
id: "/subs/sub-1/batchaccounts/acc-2",
97-
name: "acc-2",
98-
location: "brazilsouth",
99-
properties: {} as any,
100-
subscription: sub1,
101-
});
79+
expect(armSpy.get).toHaveBeenCalledTimes(0);
10280

103-
const expectedOptionsParam = {
104-
params: {
105-
"$filter": `location eq '${testBrazilAccount.location}'`
106-
}
107-
};
81+
const sizeSub = service.sizes.subscribe();
82+
expect(armSpy.get).toHaveBeenCalledTimes(2);
10883

10984
accountServiceSpy.currentAccount.next(testBrazilAccount);
11085

111-
expect(armSpy.get).toHaveBeenCalledTimes(2);
112-
expect(armSpy.get).toHaveBeenCalledWith(
113-
"subscriptions/sub1/providers/Microsoft.Compute/skus", expectedOptionsParam);
86+
await service.sizes.pipe(take(1)).toPromise();
87+
expect(armSpy.get).toHaveBeenCalledTimes(4);
88+
expect(armSpy.get).toHaveBeenCalledWith(brazilCloudServiceQuery);
89+
expect(armSpy.get).toHaveBeenCalledWith(brazilVMQuery);
11490
sizeSub.unsubscribe();
11591
});
11692

@@ -119,16 +95,6 @@ describe("VMSizeService", () => {
11995
expect(sizes).not.toBeFalsy();
12096

12197
expect(sizes!.toJS()).toEqual([
122-
{
123-
id: "standard_a0",
124-
name: "Standard_A0",
125-
numberOfCores: 1,
126-
numberOfGpus: 0,
127-
osDiskSizeInMB: 1047552,
128-
resourceDiskSizeInMB: 20480,
129-
memoryInMB: 768,
130-
maxDataDiskCount: 1,
131-
},
13298
{
13399
id: "standard_a1",
134100
name: "Standard_A1",
@@ -139,16 +105,6 @@ describe("VMSizeService", () => {
139105
memoryInMB: 1792,
140106
maxDataDiskCount: 2,
141107
},
142-
{
143-
id: "small",
144-
name: "small",
145-
numberOfCores: 1,
146-
numberOfGpus: 0,
147-
osDiskSizeInMB: 1047552,
148-
resourceDiskSizeInMB: 20480,
149-
memoryInMB: 768,
150-
maxDataDiskCount: 1,
151-
},
152108
{
153109
id: "standard_d1",
154110
name: "Standard_D1",
@@ -166,7 +122,7 @@ describe("VMSizeService", () => {
166122
armSpy = {
167123
get: jasmine.createSpy("arm.get").and.returnValue(of(badResponseIsNaN)),
168124
};
169-
const serviceWithNaN = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
125+
const serviceWithNaN = new VmSizeService(armSpy, accountServiceSpy);
170126
const sizes = await serviceWithNaN.sizes.pipe(take(1)).toPromise();
171127
expect(sizes).not.toBeFalsy();
172128

@@ -188,7 +144,7 @@ describe("VMSizeService", () => {
188144
armSpy = {
189145
get: jasmine.createSpy("arm.get").and.returnValue(of(responseWithExtraCapability)),
190146
};
191-
const serviceWithExtraCap = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
147+
const serviceWithExtraCap = new VmSizeService(armSpy, accountServiceSpy);
192148
const sizes = await serviceWithExtraCap.sizes.pipe(take(1)).toPromise();
193149
expect(sizes).not.toBeFalsy();
194150

@@ -206,7 +162,7 @@ describe("VMSizeService", () => {
206162
]);
207163
});
208164

209-
it("fitlers the IAAS sizes", async () => {
165+
it("filters the IAAS sizes", async () => {
210166
const sizes = await service.virtualMachineSizes.pipe(take(1)).toPromise();
211167
expect(sizes).not.toBeFalsy();
212168
expect(sizes!.toJS().map(x => x.id)).toEqual([
@@ -215,7 +171,7 @@ describe("VMSizeService", () => {
215171
]);
216172
});
217173

218-
it("fitlers the Cloud Service sizes", async () => {
174+
it("filters the Cloud Service sizes", async () => {
219175
const sizes = await service.cloudServiceSizes.pipe(take(1)).toPromise();
220176
expect(sizes).not.toBeFalsy();
221177
expect(sizes!.toJS().map(x => x.id)).toEqual([
@@ -226,6 +182,10 @@ describe("VMSizeService", () => {
226182

227183
it("returns null for the sizes when using local batch account", async () => {
228184
accountServiceSpy.currentAccount.next(new LocalBatchAccount({}));
185+
const vmSizes = await service.virtualMachineSizes.pipe(take(1)).toPromise();
186+
expect(vmSizes).toBeFalsy();
187+
const cloudServiceSizes = await service.cloudServiceSizes.pipe(take(1)).toPromise();
188+
expect(cloudServiceSizes).toBeFalsy();
229189
const sizes = await service.sizes.pipe(take(1)).toPromise();
230190
expect(sizes).toBeFalsy();
231191
});

0 commit comments

Comments
 (0)