@@ -3,20 +3,41 @@ import { BehaviorSubject, of } from "rxjs";
33import { take } from "rxjs/operators" ;
44import { VmSizeService } from "./vm-size.service" ;
55import {
6+ vmSizeSampleResponse as vmSizesResponse ,
67 badResponseIsNaN ,
7- responseWithExtraCapability ,
8- virtualMachineResponse ,
9- cloudServiceResponse
8+ responseWithExtraCapability
109} from "./vmsize_sample_responses" ;
1110
1211const sub1 = new ArmSubscription ( {
1312 id : "/subscriptions/sub1" ,
1413 subscriptionId : "sub1" ,
1514} ) ;
1615
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+
1737describe ( "VMSizeService" , ( ) => {
1838 let service : VmSizeService ;
1939 let armSpy ;
40+ let githubDataSpy ;
2041 let accountServiceSpy ;
2142
2243 const testWestusAccount = new ArmBatchAccount ( {
@@ -27,66 +48,69 @@ describe("VMSizeService", () => {
2748 subscription : sub1 ,
2849 } ) ;
2950
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-
4551 beforeEach ( ( ) => {
4652 armSpy = {
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 ) )
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 ) ) ) ,
5258 } ;
5359
5460 accountServiceSpy = {
5561 currentAccount : new BehaviorSubject ( testWestusAccount ) ,
5662 } ;
57- service = new VmSizeService ( armSpy , accountServiceSpy ) ;
63+ service = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
5864 } ) ;
5965
6066 afterEach ( ( ) => {
6167 service . ngOnDestroy ( ) ;
6268 } ) ;
6369
6470 it ( "use the batch account subscription and location for the sizes" , async ( ) => {
65- expect ( armSpy . get ) . toHaveBeenCalledTimes ( 0 ) ;
6671 await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
67- expect ( armSpy . get ) . toHaveBeenCalledWith ( westusVMQuery ) ;
68- expect ( armSpy . get ) . toHaveBeenCalledWith ( westusCloudServiceQuery ) ;
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 ) ;
6982 } ) ;
7083
7184 it ( "only calls the vm sizes api once per account" , async ( ) => {
7285 await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
73- expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
86+ expect ( armSpy . get ) . toHaveBeenCalledOnce ( ) ;
7487 await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
75- expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
88+ expect ( armSpy . get ) . toHaveBeenCalledOnce ( ) ;
7689 } ) ;
7790
7891 it ( "calls again when batch account changes" , async ( ) => {
79- expect ( armSpy . get ) . toHaveBeenCalledTimes ( 0 ) ;
80-
8192 const sizeSub = service . sizes . subscribe ( ) ;
82- expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
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+ } ) ;
102+
103+ const expectedOptionsParam = {
104+ params : {
105+ "$filter" : `location eq '${ testBrazilAccount . location } '`
106+ }
107+ } ;
83108
84109 accountServiceSpy . currentAccount . next ( testBrazilAccount ) ;
85110
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 ) ;
111+ expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
112+ expect ( armSpy . get ) . toHaveBeenCalledWith (
113+ "subscriptions/sub1/providers/Microsoft.Compute/skus" , expectedOptionsParam ) ;
90114 sizeSub . unsubscribe ( ) ;
91115 } ) ;
92116
@@ -95,6 +119,16 @@ describe("VMSizeService", () => {
95119 expect ( sizes ) . not . toBeFalsy ( ) ;
96120
97121 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+ } ,
98132 {
99133 id : "standard_a1" ,
100134 name : "Standard_A1" ,
@@ -105,6 +139,16 @@ describe("VMSizeService", () => {
105139 memoryInMB : 1792 ,
106140 maxDataDiskCount : 2 ,
107141 } ,
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+ } ,
108152 {
109153 id : "standard_d1" ,
110154 name : "Standard_D1" ,
@@ -122,7 +166,7 @@ describe("VMSizeService", () => {
122166 armSpy = {
123167 get : jasmine . createSpy ( "arm.get" ) . and . returnValue ( of ( badResponseIsNaN ) ) ,
124168 } ;
125- const serviceWithNaN = new VmSizeService ( armSpy , accountServiceSpy ) ;
169+ const serviceWithNaN = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
126170 const sizes = await serviceWithNaN . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
127171 expect ( sizes ) . not . toBeFalsy ( ) ;
128172
@@ -144,7 +188,7 @@ describe("VMSizeService", () => {
144188 armSpy = {
145189 get : jasmine . createSpy ( "arm.get" ) . and . returnValue ( of ( responseWithExtraCapability ) ) ,
146190 } ;
147- const serviceWithExtraCap = new VmSizeService ( armSpy , accountServiceSpy ) ;
191+ const serviceWithExtraCap = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
148192 const sizes = await serviceWithExtraCap . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
149193 expect ( sizes ) . not . toBeFalsy ( ) ;
150194
@@ -162,7 +206,7 @@ describe("VMSizeService", () => {
162206 ] ) ;
163207 } ) ;
164208
165- it ( "filters the IAAS sizes" , async ( ) => {
209+ it ( "fitlers the IAAS sizes" , async ( ) => {
166210 const sizes = await service . virtualMachineSizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
167211 expect ( sizes ) . not . toBeFalsy ( ) ;
168212 expect ( sizes ! . toJS ( ) . map ( x => x . id ) ) . toEqual ( [
@@ -171,7 +215,7 @@ describe("VMSizeService", () => {
171215 ] ) ;
172216 } ) ;
173217
174- it ( "filters the Cloud Service sizes" , async ( ) => {
218+ it ( "fitlers the Cloud Service sizes" , async ( ) => {
175219 const sizes = await service . cloudServiceSizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
176220 expect ( sizes ) . not . toBeFalsy ( ) ;
177221 expect ( sizes ! . toJS ( ) . map ( x => x . id ) ) . toEqual ( [
@@ -182,10 +226,6 @@ describe("VMSizeService", () => {
182226
183227 it ( "returns null for the sizes when using local batch account" , async ( ) => {
184228 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 ( ) ;
189229 const sizes = await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
190230 expect ( sizes ) . toBeFalsy ( ) ;
191231 } ) ;
0 commit comments