Skip to content

Commit

Permalink
Merge pull request #2437 from Azure/rechen/revert-2400
Browse files Browse the repository at this point in the history
Revert "Update to call List Supported Virtual Machine and Cloud Service SKUs (#2400)"
  • Loading branch information
cRui861 authored Feb 10, 2022
2 parents bc4944b + bd30b07 commit e6c888d
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("ToggleFilterButtonComponent", () => {
});
});

describe("when filter is empty", () => {
describe("when fitler 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("filter", () => {
it("fitler", () => {
testComponent.filter = "m";
fixture.detectChanges();

Expand Down
128 changes: 84 additions & 44 deletions src/app/services/compute/vm-size.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,41 @@ import { BehaviorSubject, of } from "rxjs";
import { take } from "rxjs/operators";
import { VmSizeService } from "./vm-size.service";
import {
vmSizeSampleResponse as vmSizesResponse,
badResponseIsNaN,
responseWithExtraCapability,
virtualMachineResponse,
cloudServiceResponse
responseWithExtraCapability
} 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 @@ -27,66 +48,69 @@ 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")
.withArgs(westusVMQuery).and.returnValue(of(virtualMachineResponse))
.withArgs(westusCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
.withArgs(brazilCloudServiceQuery).and.returnValue(of(cloudServiceResponse))
.withArgs(brazilVMQuery).and.returnValue(of(virtualMachineResponse))
get: jasmine.createSpy("arm.get").and.returnValue(of(vmSizesResponse)),
};

githubDataSpy = {
get: jasmine.createSpy("githubData.get").and.returnValue(of(JSON.stringify(githubDataResponse))),
};

accountServiceSpy = {
currentAccount: new BehaviorSubject(testWestusAccount),
};
service = new VmSizeService(armSpy, accountServiceSpy);
service = new VmSizeService(armSpy, githubDataSpy, 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).toHaveBeenCalledWith(westusVMQuery);
expect(armSpy.get).toHaveBeenCalledWith(westusCloudServiceQuery);
expect(armSpy.get).toHaveBeenCalledOnce();

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

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

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

it("calls again when batch account changes", async () => {
expect(armSpy.get).toHaveBeenCalledTimes(0);

const sizeSub = service.sizes.subscribe();
expect(armSpy.get).toHaveBeenCalledTimes(2);
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,
});

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

accountServiceSpy.currentAccount.next(testBrazilAccount);

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

Expand All @@ -95,6 +119,16 @@ 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 @@ -105,6 +139,16 @@ 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 @@ -122,7 +166,7 @@ describe("VMSizeService", () => {
armSpy = {
get: jasmine.createSpy("arm.get").and.returnValue(of(badResponseIsNaN)),
};
const serviceWithNaN = new VmSizeService(armSpy, accountServiceSpy);
const serviceWithNaN = new VmSizeService(armSpy, githubDataSpy, accountServiceSpy);
const sizes = await serviceWithNaN.sizes.pipe(take(1)).toPromise();
expect(sizes).not.toBeFalsy();

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

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

it("filters the IAAS sizes", async () => {
it("fitlers 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 @@ -171,7 +215,7 @@ describe("VMSizeService", () => {
]);
});

it("filters the Cloud Service sizes", async () => {
it("fitlers 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 @@ -182,10 +226,6 @@ 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 e6c888d

Please sign in to comment.