@@ -3,41 +3,20 @@ import { BehaviorSubject, of } from "rxjs";
3
3
import { take } from "rxjs/operators" ;
4
4
import { VmSizeService } from "./vm-size.service" ;
5
5
import {
6
- vmSizeSampleResponse as vmSizesResponse ,
7
6
badResponseIsNaN ,
8
- responseWithExtraCapability
7
+ responseWithExtraCapability ,
8
+ virtualMachineResponse ,
9
+ cloudServiceResponse
9
10
} from "./vmsize_sample_responses" ;
10
11
11
12
const sub1 = new ArmSubscription ( {
12
13
id : "/subscriptions/sub1" ,
13
14
subscriptionId : "sub1" ,
14
15
} ) ;
15
16
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
-
37
17
describe ( "VMSizeService" , ( ) => {
38
18
let service : VmSizeService ;
39
19
let armSpy ;
40
- let githubDataSpy ;
41
20
let accountServiceSpy ;
42
21
43
22
const testWestusAccount = new ArmBatchAccount ( {
@@ -48,69 +27,66 @@ describe("VMSizeService", () => {
48
27
subscription : sub1 ,
49
28
} ) ;
50
29
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
+
51
45
beforeEach ( ( ) => {
52
46
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 ) )
58
52
} ;
59
53
60
54
accountServiceSpy = {
61
55
currentAccount : new BehaviorSubject ( testWestusAccount ) ,
62
56
} ;
63
- service = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
57
+ service = new VmSizeService ( armSpy , accountServiceSpy ) ;
64
58
} ) ;
65
59
66
60
afterEach ( ( ) => {
67
61
service . ngOnDestroy ( ) ;
68
62
} ) ;
69
63
70
64
it ( "use the batch account subscription and location for the sizes" , async ( ) => {
65
+ expect ( armSpy . get ) . toHaveBeenCalledTimes ( 0 ) ;
71
66
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 ) ;
82
69
} ) ;
83
70
84
71
it ( "only calls the vm sizes api once per account" , async ( ) => {
85
72
await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
86
- expect ( armSpy . get ) . toHaveBeenCalledOnce ( ) ;
73
+ expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
87
74
await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
88
- expect ( armSpy . get ) . toHaveBeenCalledOnce ( ) ;
75
+ expect ( armSpy . get ) . toHaveBeenCalledTimes ( 2 ) ;
89
76
} ) ;
90
77
91
78
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 ) ;
102
80
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 ) ;
108
83
109
84
accountServiceSpy . currentAccount . next ( testBrazilAccount ) ;
110
85
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 ) ;
114
90
sizeSub . unsubscribe ( ) ;
115
91
} ) ;
116
92
@@ -119,16 +95,6 @@ describe("VMSizeService", () => {
119
95
expect ( sizes ) . not . toBeFalsy ( ) ;
120
96
121
97
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
- } ,
132
98
{
133
99
id : "standard_a1" ,
134
100
name : "Standard_A1" ,
@@ -139,16 +105,6 @@ describe("VMSizeService", () => {
139
105
memoryInMB : 1792 ,
140
106
maxDataDiskCount : 2 ,
141
107
} ,
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
- } ,
152
108
{
153
109
id : "standard_d1" ,
154
110
name : "Standard_D1" ,
@@ -166,7 +122,7 @@ describe("VMSizeService", () => {
166
122
armSpy = {
167
123
get : jasmine . createSpy ( "arm.get" ) . and . returnValue ( of ( badResponseIsNaN ) ) ,
168
124
} ;
169
- const serviceWithNaN = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
125
+ const serviceWithNaN = new VmSizeService ( armSpy , accountServiceSpy ) ;
170
126
const sizes = await serviceWithNaN . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
171
127
expect ( sizes ) . not . toBeFalsy ( ) ;
172
128
@@ -188,7 +144,7 @@ describe("VMSizeService", () => {
188
144
armSpy = {
189
145
get : jasmine . createSpy ( "arm.get" ) . and . returnValue ( of ( responseWithExtraCapability ) ) ,
190
146
} ;
191
- const serviceWithExtraCap = new VmSizeService ( armSpy , githubDataSpy , accountServiceSpy ) ;
147
+ const serviceWithExtraCap = new VmSizeService ( armSpy , accountServiceSpy ) ;
192
148
const sizes = await serviceWithExtraCap . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
193
149
expect ( sizes ) . not . toBeFalsy ( ) ;
194
150
@@ -206,7 +162,7 @@ describe("VMSizeService", () => {
206
162
] ) ;
207
163
} ) ;
208
164
209
- it ( "fitlers the IAAS sizes" , async ( ) => {
165
+ it ( "filters the IAAS sizes" , async ( ) => {
210
166
const sizes = await service . virtualMachineSizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
211
167
expect ( sizes ) . not . toBeFalsy ( ) ;
212
168
expect ( sizes ! . toJS ( ) . map ( x => x . id ) ) . toEqual ( [
@@ -215,7 +171,7 @@ describe("VMSizeService", () => {
215
171
] ) ;
216
172
} ) ;
217
173
218
- it ( "fitlers the Cloud Service sizes" , async ( ) => {
174
+ it ( "filters the Cloud Service sizes" , async ( ) => {
219
175
const sizes = await service . cloudServiceSizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
220
176
expect ( sizes ) . not . toBeFalsy ( ) ;
221
177
expect ( sizes ! . toJS ( ) . map ( x => x . id ) ) . toEqual ( [
@@ -226,6 +182,10 @@ describe("VMSizeService", () => {
226
182
227
183
it ( "returns null for the sizes when using local batch account" , async ( ) => {
228
184
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 ( ) ;
229
189
const sizes = await service . sizes . pipe ( take ( 1 ) ) . toPromise ( ) ;
230
190
expect ( sizes ) . toBeFalsy ( ) ;
231
191
} ) ;
0 commit comments