@@ -25,7 +25,8 @@ import (
2525// DummyCloudInfoStore type implements the CloudInfoStore interface for mockig of external calls
2626// the struct is to be extended according to the needs of test cases
2727type DummyCloudInfoStore struct {
28- TcId string
28+ TcId string
29+ customVMs []types.VMInfo
2930 // implement the interface
3031 CloudInfoStore
3132}
@@ -53,6 +54,10 @@ func (dcis *DummyCloudInfoStore) GetVm(provider, service, region string) ([]type
5354 case notCached :
5455 return nil , false
5556 default :
57+ // If customVMs is provided, use it; otherwise use default VMs
58+ if dcis .customVMs != nil {
59+ return dcis .customVMs , true
60+ }
5661 return []types.VMInfo {
5762 {Category : types .CategoryGeneral , Series : "series0" , Type : "instanceType00" },
5863 {Category : types .CategoryCompute , Series : "series1" , Type : "instanceType10" },
@@ -212,13 +217,15 @@ func TestCachingCloudInfo_GetRegions(t *testing.T) {
212217
213218func TestCloudInfo_GetSeries (t * testing.T ) {
214219 tests := []struct {
215- name string
216- ciStore CloudInfoStore
217- checker func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error )
220+ name string
221+ provider string
222+ ciStore CloudInfoStore
223+ checker func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error )
218224 }{
219225 {
220- name : "successfully retrieved the series" ,
221- ciStore : & DummyCloudInfoStore {},
226+ name : "successfully retrieved the series" ,
227+ provider : "dummyProvider" ,
228+ ciStore : & DummyCloudInfoStore {},
222229 checker : func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error ) {
223230 assert .Nil (t , err , "the error should be nil" )
224231
@@ -242,19 +249,77 @@ func TestCloudInfo_GetSeries(t *testing.T) {
242249 },
243250 },
244251 {
245- name : "failed to retrieve series" ,
246- ciStore : & DummyCloudInfoStore {TcId : notCached },
252+ name : "failed to retrieve series" ,
253+ provider : "dummyProvider" ,
254+ ciStore : & DummyCloudInfoStore {TcId : notCached },
247255 checker : func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error ) {
248256 assert .Nil (t , seriesDetails , "the seriesDetails should be nil" )
249257 assert .EqualError (t , err , "VMs Information not yet cached" )
250258 },
251259 },
260+ {
261+ name : "Azure instances with empty category mapped to General purpose" ,
262+ provider : "azure" ,
263+ ciStore : & DummyCloudInfoStore {
264+ customVMs : []types.VMInfo {
265+ {Category : "" , Series : "DASv5" , Type : "Standard_D16as_v5" },
266+ {Category : "" , Series : "DASv5" , Type : "Standard_D2as_v5" },
267+ {Category : types .CategoryMemory , Series : "Ev3" , Type : "Standard_E16_v3" },
268+ },
269+ },
270+ checker : func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error ) {
271+ assert .Nil (t , err , "the error should be nil" )
272+
273+ // Empty categories should be mapped to "General purpose" for Azure
274+ assert .Equal (t , categorySeriesMap , map [string ]map [string ][]string {
275+ types .CategoryGeneral : {
276+ "DASv5" : []string {"Standard_D16as_v5" , "Standard_D2as_v5" },
277+ },
278+ types .CategoryMemory : {
279+ "Ev3" : []string {"Standard_E16_v3" },
280+ },
281+ })
282+
283+ assert .ElementsMatch (t , seriesDetails , []types.SeriesDetails {
284+ {Series : "DASv5" , Category : types .CategoryGeneral , InstanceTypes : []string {"Standard_D16as_v5" , "Standard_D2as_v5" }},
285+ {Series : "Ev3" , Category : types .CategoryMemory , InstanceTypes : []string {"Standard_E16_v3" }},
286+ })
287+ },
288+ },
289+ {
290+ name : "non-Azure instances with empty category remain empty" ,
291+ provider : "amazon" ,
292+ ciStore : & DummyCloudInfoStore {
293+ customVMs : []types.VMInfo {
294+ {Category : "" , Series : "t3" , Type : "t3.micro" },
295+ {Category : types .CategoryGeneral , Series : "m5" , Type : "m5.large" },
296+ },
297+ },
298+ checker : func (categorySeriesMap map [string ]map [string ][]string , seriesDetails []types.SeriesDetails , err error ) {
299+ assert .Nil (t , err , "the error should be nil" )
300+
301+ // Empty categories should remain empty for non-Azure providers
302+ assert .Equal (t , categorySeriesMap , map [string ]map [string ][]string {
303+ "" : {
304+ "t3" : []string {"t3.micro" },
305+ },
306+ types .CategoryGeneral : {
307+ "m5" : []string {"m5.large" },
308+ },
309+ })
310+
311+ assert .ElementsMatch (t , seriesDetails , []types.SeriesDetails {
312+ {Series : "t3" , Category : "" , InstanceTypes : []string {"t3.micro" }},
313+ {Series : "m5" , Category : types .CategoryGeneral , InstanceTypes : []string {"m5.large" }},
314+ })
315+ },
316+ },
252317 }
253318 for _ , test := range tests {
254319 t .Run (test .name , func (t * testing.T ) {
255320 info , _ := NewCloudInfo ([]string {}, & DummyCloudInfoStore {}, cloudinfoLogger )
256321 info .cloudInfoStore = test .ciStore
257- test .checker (info .GetSeriesDetails ("dummyProvider" , "dummyService" , "dummyRegion" ))
322+ test .checker (info .GetSeriesDetails (test . provider , "dummyService" , "dummyRegion" ))
258323 })
259324 }
260325}
0 commit comments