@@ -100,6 +100,22 @@ func TestUpdateEvaluationEnvHardware(t *testing.T) {
100100 "DCU_NUM" : "1" ,
101101 },
102102 },
103+ {
104+ name : "TPU set when others are empty" ,
105+ env : make (map [string ]string ),
106+ hardware : types.HardWare {
107+ Gpu : types.Processor {Num : "" },
108+ Npu : types.Processor {Num : "" },
109+ Gcu : types.Processor {Num : "" },
110+ Mlu : types.Processor {Num : "" },
111+ Dcu : types.Processor {Num : "" },
112+ Tpu : types.Processor {Num : "1" },
113+ },
114+ expected : map [string ]string {
115+ "TPU_NUM" : "1" ,
116+ "GPU_NUM" : "1" ,
117+ },
118+ },
103119 {
104120 name : "No hardware set" ,
105121 env : make (map [string ]string ),
@@ -210,6 +226,14 @@ func TestGetXPUNumber(t *testing.T) {
210226 want : 1 ,
211227 wantErr : false ,
212228 },
229+ {
230+ name : "Only Tpu specified" ,
231+ hardware : types.HardWare {
232+ Tpu : types.Processor {Num : "3" },
233+ },
234+ want : 3 ,
235+ wantErr : false ,
236+ },
213237 {
214238 name : "GPU takes priority over others" ,
215239 hardware : types.HardWare {
@@ -434,6 +458,18 @@ func TestResourceType(t *testing.T) {
434458 },
435459 expected : types .ResourceTypeGPU ,
436460 },
461+ {
462+ name : "TPU when TPU Num is not empty and others are empty" ,
463+ hardware : types.HardWare {
464+ Gpu : types.Processor {Num : "" },
465+ Npu : types.Processor {Num : "" },
466+ Mlu : types.Processor {Num : "" },
467+ Gcu : types.Processor {Num : "" },
468+ Dcu : types.Processor {Num : "" },
469+ Tpu : types.Processor {Num : "1" },
470+ },
471+ expected : types .ResourceTypeTPU ,
472+ },
437473 }
438474
439475 for _ , tt := range tests {
@@ -445,3 +481,30 @@ func TestResourceType(t *testing.T) {
445481 })
446482 }
447483}
484+
485+ func TestContainsGraphicResource (t * testing.T ) {
486+ tests := []struct {
487+ name string
488+ hardware types.HardWare
489+ want bool
490+ }{
491+ {
492+ name : "cpu only" ,
493+ hardware : types.HardWare {Cpu : types.CPU {Num : "2" }, Memory : "4Gi" },
494+ want : false ,
495+ },
496+ {
497+ name : "tpu is graphic resource" ,
498+ hardware : types.HardWare {
499+ Tpu : types.Processor {Num : "1" },
500+ },
501+ want : true ,
502+ },
503+ }
504+
505+ for _ , tt := range tests {
506+ t .Run (tt .name , func (t * testing.T ) {
507+ require .Equal (t , tt .want , ContainsGraphicResource (tt .hardware ))
508+ })
509+ }
510+ }
0 commit comments