@@ -69,3 +69,120 @@ func TestGetRuntimeString(t *testing.T) {
6969 })
7070 }
7171}
72+
73+ func TestIsValidWorkloadConfig (t * testing.T ) {
74+ tests := []struct {
75+ config string
76+ want bool
77+ }{
78+ {gpuWorkloadConfigContainer , true }, {gpuWorkloadConfigVMPassthrough , true }, {gpuWorkloadConfigVMVgpu , true },
79+ {"invalid" , false }, {"" , false },
80+ }
81+ for _ , tc := range tests {
82+ if got := isValidWorkloadConfig (tc .config ); got != tc .want {
83+ t .Errorf ("isValidWorkloadConfig(%q) = %v, want %v" , tc .config , got , tc .want )
84+ }
85+ }
86+ }
87+
88+ func TestHasOperandsDisabled (t * testing.T ) {
89+ tests := []struct {
90+ labels map [string ]string
91+ want bool
92+ }{
93+ {map [string ]string {commonOperandsLabelKey : "false" }, true },
94+ {map [string ]string {commonOperandsLabelKey : commonOperandsLabelValue }, false },
95+ {map [string ]string {}, false },
96+ }
97+ for _ , tc := range tests {
98+ if got := hasOperandsDisabled (tc .labels ); got != tc .want {
99+ t .Errorf ("hasOperandsDisabled(%v) = %v, want %v" , tc .labels , got , tc .want )
100+ }
101+ }
102+ }
103+
104+ func TestHasNFDLabels (t * testing.T ) {
105+ tests := []struct {
106+ labels map [string ]string
107+ want bool
108+ }{
109+ {map [string ]string {nfdLabelPrefix + "cpu" : "true" }, true },
110+ {map [string ]string {"other-label" : "value" }, false },
111+ {map [string ]string {}, false },
112+ }
113+ for _ , tc := range tests {
114+ if got := hasNFDLabels (tc .labels ); got != tc .want {
115+ t .Errorf ("hasNFDLabels(%v) = %v, want %v" , tc .labels , got , tc .want )
116+ }
117+ }
118+ }
119+
120+ func TestHasMIGManagerLabel (t * testing.T ) {
121+ tests := []struct {
122+ labels map [string ]string
123+ want bool
124+ }{
125+ {map [string ]string {migManagerLabelKey : migManagerLabelValue }, true },
126+ {map [string ]string {"other" : "value" }, false },
127+ }
128+ for _ , tc := range tests {
129+ if got := hasMIGManagerLabel (tc .labels ); got != tc .want {
130+ t .Errorf ("hasMIGManagerLabel(%v) = %v, want %v" , tc .labels , got , tc .want )
131+ }
132+ }
133+ }
134+
135+ func TestHasCommonGPULabel (t * testing.T ) {
136+ tests := []struct {
137+ labels map [string ]string
138+ want bool
139+ }{
140+ {map [string ]string {commonGPULabelKey : commonGPULabelValue }, true },
141+ {map [string ]string {commonGPULabelKey : "false" }, false },
142+ {map [string ]string {}, false },
143+ }
144+ for _ , tc := range tests {
145+ if got := hasCommonGPULabel (tc .labels ); got != tc .want {
146+ t .Errorf ("hasCommonGPULabel(%v) = %v, want %v" , tc .labels , got , tc .want )
147+ }
148+ }
149+ }
150+
151+ func TestHasGPULabels (t * testing.T ) {
152+ tests := []struct {
153+ labels map [string ]string
154+ want bool
155+ }{
156+ {map [string ]string {nfdLabelPrefix + "pci-10de.present" : "true" }, true },
157+ {map [string ]string {nfdLabelPrefix + "pci-0302_10de.present" : "true" }, true },
158+ {map [string ]string {nfdLabelPrefix + "pci-0300_10de.present" : "true" }, true },
159+ {map [string ]string {nfdLabelPrefix + "pci-10de.present" : "false" }, false },
160+ {map [string ]string {"other" : "true" }, false },
161+ }
162+ for _ , tc := range tests {
163+ if got := hasGPULabels (tc .labels ); got != tc .want {
164+ t .Errorf ("hasGPULabels(%v) = %v, want %v" , tc .labels , got , tc .want )
165+ }
166+ }
167+ }
168+
169+ func TestHasMIGCapableGPU (t * testing.T ) {
170+ tests := []struct {
171+ labels map [string ]string
172+ want bool
173+ }{
174+ {map [string ]string {migCapableLabelKey : migCapableLabelValue }, true },
175+ {map [string ]string {migCapableLabelKey : "false" }, false },
176+ {map [string ]string {gpuProductLabelKey : "NVIDIA-A100" }, true },
177+ {map [string ]string {gpuProductLabelKey : "NVIDIA-H100" }, true },
178+ {map [string ]string {gpuProductLabelKey : "NVIDIA-A30" }, true },
179+ {map [string ]string {gpuProductLabelKey : "NVIDIA-T4" }, false },
180+ {map [string ]string {vgpuHostDriverLabelKey : "535.54" }, false },
181+ {map [string ]string {}, false },
182+ }
183+ for _ , tc := range tests {
184+ if got := hasMIGCapableGPU (tc .labels ); got != tc .want {
185+ t .Errorf ("hasMIGCapableGPU(%v) = %v, want %v" , tc .labels , got , tc .want )
186+ }
187+ }
188+ }
0 commit comments