Skip to content

Commit

Permalink
Unrevert "Update to call List Supported Virtual Machine and Cloud Ser…
Browse files Browse the repository at this point in the history
…vice SKUs (#2400)"

8a7424b

Batch Service supports VM SKU API so reenabling service call.
  • Loading branch information
gingi committed Apr 1, 2022
1 parent e7f521e commit 4e4eb6c
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("ToggleFilterButtonComponent", () => {
});
});

describe("when fitler is empty", () => {
describe("when filter is empty", () => {
it("should not show marker", () => {
expect(de.query(By.css(".filtering"))).toBeFalsy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("GalleryApplicationList", () => {
expect(apps[3].query(By.css(".logo")).nativeElement.getAttribute("src")).toEqual(applications[2].icon);
});

it("fitler", () => {
it("filter", () => {
testComponent.filter = "m";
fixture.detectChanges();

Expand Down
128 changes: 44 additions & 84 deletions src/app/services/compute/vm-size.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,20 @@ import { BehaviorSubject, of } from "rxjs";
import { take } from "rxjs/operators";
import { VmSizeService } from "./vm-size.service";
import {
vmSizeSampleResponse as vmSizesResponse,
badResponseIsNaN,
responseWithExtraCapability
responseWithExtraCapability,
virtualMachineResponse,
cloudServiceResponse
} from "./vmsize_sample_responses";

const sub1 = new ArmSubscription({
id: "/subscriptions/sub1",
subscriptionId: "sub1",
});

const githubDataResponse = {
category: {
all: [".*"],
memory: [
"^standard_d[0-9a-z]*$",
],
},
all: [
"^standard_d[0-9]*$",
],
paas: [
"small",
"medium",
"large",
"extralarge",
],
iaas: [
"^standard_a[1-9][0-9]*$",
],
};

describe("VMSizeService", () => {
let service: VmSizeService;
let armSpy;
let githubDataSpy;
let accountServiceSpy;

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

const testBrazilAccount = new ArmBatchAccount({
id: "/subs/sub-1/batchaccounts/acc-2",
name: "acc-2",
location: "brazilsouth",
properties: {} as any,
subscription: sub1,
});

// westus account
const westusCloudServiceQuery = `/subscriptions/${testWestusAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testWestusAccount.location}/cloudServiceSkus?api-version=2021-06-01`;
const westusVMQuery = `/subscriptions/${testWestusAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testWestusAccount.location}/virtualMachineSkus?api-version=2021-06-01`;
// brazilsouth account
const brazilCloudServiceQuery = `/subscriptions/${testBrazilAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testBrazilAccount.location}/cloudServiceSkus?api-version=2021-06-01`
const brazilVMQuery = `/subscriptions/${testBrazilAccount.subscription.subscriptionId}/providers/Microsoft.Batch/locations/${testBrazilAccount.location}/virtualMachineSkus?api-version=2021-06-01`

beforeEach(() => {
armSpy = {
get: jasmine.createSpy("arm.get").and.returnValue(of(vmSizesResponse)),
};

githubDataSpy = {
get: jasmine.createSpy("githubData.get").and.returnValue(of(JSON.stringify(githubDataResponse))),
get: jasmine.createSpy("arm.get")
.withArgs(westusVMQuery).and.returnValue(of(virtualMachineResponse))
.withArgs(westusCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
.withArgs(brazilCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
.withArgs(brazilVMQuery).and.returnValue(of(virtualMachineResponse))
};

accountServiceSpy = {
currentAccount: new BehaviorSubject(testWestusAccount),
};
service = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
service = new VmSizeService(armSpy, accountServiceSpy);
});

afterEach(() => {
service.ngOnDestroy();
});

it("use the batch account subscription and location for the sizes", async () => {
expect(armSpy.get).toHaveBeenCalledTimes(0);
await service.sizes.pipe(take(1)).toPromise();
expect(armSpy.get).toHaveBeenCalledOnce();

const expectedOptionsParam = {
params: {
"$filter": `location eq '${testWestusAccount.location}'`
}
};

expect(armSpy.get).toHaveBeenCalledWith(
"subscriptions/sub1/providers/Microsoft.Compute/skus", expectedOptionsParam);
expect(armSpy.get).toHaveBeenCalledWith(westusVMQuery);
expect(armSpy.get).toHaveBeenCalledWith(westusCloudServiceQuery);
});

it("only calls the vm sizes api once per account", async () => {
await service.sizes.pipe(take(1)).toPromise();
expect(armSpy.get).toHaveBeenCalledOnce();
expect(armSpy.get).toHaveBeenCalledTimes(2);
await service.sizes.pipe(take(1)).toPromise();
expect(armSpy.get).toHaveBeenCalledOnce();
expect(armSpy.get).toHaveBeenCalledTimes(2);
});

it("calls again when batch account changes", async () => {
const sizeSub = service.sizes.subscribe();
expect(armSpy.get).toHaveBeenCalledTimes(1);

const testBrazilAccount = new ArmBatchAccount({
id: "/subs/sub-1/batchaccounts/acc-2",
name: "acc-2",
location: "brazilsouth",
properties: {} as any,
subscription: sub1,
});
expect(armSpy.get).toHaveBeenCalledTimes(0);

const expectedOptionsParam = {
params: {
"$filter": `location eq '${testBrazilAccount.location}'`
}
};
const sizeSub = service.sizes.subscribe();
expect(armSpy.get).toHaveBeenCalledTimes(2);

accountServiceSpy.currentAccount.next(testBrazilAccount);

expect(armSpy.get).toHaveBeenCalledTimes(2);
expect(armSpy.get).toHaveBeenCalledWith(
"subscriptions/sub1/providers/Microsoft.Compute/skus", expectedOptionsParam);
await service.sizes.pipe(take(1)).toPromise();
expect(armSpy.get).toHaveBeenCalledTimes(4);
expect(armSpy.get).toHaveBeenCalledWith(brazilCloudServiceQuery);
expect(armSpy.get).toHaveBeenCalledWith(brazilVMQuery);
sizeSub.unsubscribe();
});

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

expect(sizes!.toJS()).toEqual([
{
id: "standard_a0",
name: "Standard_A0",
numberOfCores: 1,
numberOfGpus: 0,
osDiskSizeInMB: 1047552,
resourceDiskSizeInMB: 20480,
memoryInMB: 768,
maxDataDiskCount: 1,
},
{
id: "standard_a1",
name: "Standard_A1",
Expand All @@ -139,16 +105,6 @@ describe("VMSizeService", () => {
memoryInMB: 1792,
maxDataDiskCount: 2,
},
{
id: "small",
name: "small",
numberOfCores: 1,
numberOfGpus: 0,
osDiskSizeInMB: 1047552,
resourceDiskSizeInMB: 20480,
memoryInMB: 768,
maxDataDiskCount: 1,
},
{
id: "standard_d1",
name: "Standard_D1",
Expand All @@ -166,7 +122,7 @@ describe("VMSizeService", () => {
armSpy = {
get: jasmine.createSpy("arm.get").and.returnValue(of(badResponseIsNaN)),
};
const serviceWithNaN = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
const serviceWithNaN = new VmSizeService(armSpy, accountServiceSpy);
const sizes = await serviceWithNaN.sizes.pipe(take(1)).toPromise();
expect(sizes).not.toBeFalsy();

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

Expand All @@ -206,7 +162,7 @@ describe("VMSizeService", () => {
]);
});

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

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

it("returns null for the sizes when using local batch account", async () => {
accountServiceSpy.currentAccount.next(new LocalBatchAccount({}));
const vmSizes = await service.virtualMachineSizes.pipe(take(1)).toPromise();
expect(vmSizes).toBeFalsy();
const cloudServiceSizes = await service.cloudServiceSizes.pipe(take(1)).toPromise();
expect(cloudServiceSizes).toBeFalsy();
const sizes = await service.sizes.pipe(take(1)).toPromise();
expect(sizes).toBeFalsy();
});
Expand Down
Loading

0 comments on commit 4e4eb6c

Please sign in to comment.