@@ -28,30 +28,36 @@ import (
2828)
2929
3030func TestSpec (t * testing.T ) {
31+ minimalSpec := & specs.Spec {
32+ Kind : "nvidia.com/gpu" ,
33+ Devices : []specs.Device {
34+ {
35+ Name : "one" ,
36+ ContainerEdits : specs.ContainerEdits {
37+ Env : []string {"DEVICE_FOO=bar" },
38+ },
39+ },
40+ },
41+ }
42+
3143 testCases := []struct {
3244 description string
3345 options []Option
3446 expectedNewError error
3547 transform transform.Transformer
3648 expectedSpec string
3749 }{
38- {
39- description : "default options return empty spec" ,
40- expectedSpec : `---
41- cdiVersion: 0.3.0
42- containerEdits: {}
43- devices: null
44- kind: nvidia.com/gpu
45- ` ,
46- },
4750 {
4851 description : "version is overridden" ,
49- options : []Option {WithVersion ("0.5 .0" )},
52+ options : []Option {WithVersion ("0.8 .0" ), WithRawSpec ( minimalSpec )},
5053 expectedSpec : `---
51- cdiVersion: 0.5.0
52- containerEdits: {}
53- devices: null
54+ cdiVersion: 0.8.0
5455kind: nvidia.com/gpu
56+ devices:
57+ - name: one
58+ containerEdits:
59+ env:
60+ - DEVICE_FOO=bar
5561` ,
5662 },
5763 {
@@ -60,46 +66,65 @@ kind: nvidia.com/gpu
6066 & specs.Spec {
6167 Version : "0.5.0" ,
6268 Kind : "nvidia.com/gpu" ,
63- ContainerEdits : specs.ContainerEdits {
64- Env : []string {"FOO=bar" },
69+ Devices : []specs.Device {
70+ {
71+ Name : "one" ,
72+ ContainerEdits : specs.ContainerEdits {
73+ Env : []string {"DEVICE_FOO=bar" },
74+ },
75+ },
6576 },
6677 },
6778 )},
6879 expectedSpec : `---
6980cdiVersion: 0.5.0
70- containerEdits:
71- env:
72- - FOO=bar
73- devices: null
7481kind: nvidia.com/gpu
82+ devices:
83+ - name: one
84+ containerEdits:
85+ env:
86+ - DEVICE_FOO=bar
7587` ,
7688 },
7789 {
7890 description : "raw spec with no version uses minimum version" ,
7991 options : []Option {WithRawSpec (
8092 & specs.Spec {
8193 Kind : "nvidia.com/gpu" ,
82- ContainerEdits : specs.ContainerEdits {
83- Env : []string {"FOO=bar" },
94+ Devices : []specs.Device {
95+ {
96+ Name : "one" ,
97+ ContainerEdits : specs.ContainerEdits {
98+ Env : []string {"DEVICE_FOO=bar" },
99+ },
100+ },
84101 },
85102 },
86103 )},
87104 expectedSpec : `---
88105cdiVersion: 0.3.0
89- containerEdits:
90- env:
91- - FOO=bar
92- devices: null
93106kind: nvidia.com/gpu
107+ devices:
108+ - name: one
109+ containerEdits:
110+ env:
111+ - DEVICE_FOO=bar
94112` ,
95113 },
96114 {
97115 description : "spec with host dev path uses 0.5.0 version" ,
98116 options : []Option {WithRawSpec (
99117 & specs.Spec {
100118 Kind : "nvidia.com/gpu" ,
119+ Devices : []specs.Device {
120+ {
121+ Name : "one" ,
122+ ContainerEdits : specs.ContainerEdits {
123+ Env : []string {"DEVICE_FOO=bar" },
124+ },
125+ },
126+ },
101127 ContainerEdits : specs.ContainerEdits {
102- Env : []string {"FOO=bar" },
103128 DeviceNodes : []* specs.DeviceNode {
104129 {
105130 HostPath : "/some/dev/dev0" ,
@@ -111,23 +136,32 @@ kind: nvidia.com/gpu
111136 )},
112137 expectedSpec : `---
113138cdiVersion: 0.5.0
139+ kind: nvidia.com/gpu
140+ devices:
141+ - name: one
142+ containerEdits:
143+ env:
144+ - DEVICE_FOO=bar
114145containerEdits:
115146 deviceNodes:
116- - hostPath: /some/dev/dev0
117- path: /dev/dev0
118- env:
119- - FOO=bar
120- devices: null
121- kind: nvidia.com/gpu
147+ - path: /dev/dev0
148+ hostPath: /some/dev/dev0
122149` ,
123150 },
124151 {
125152 description : "transformed spec uses minimum version" ,
126153 options : []Option {WithRawSpec (
127154 & specs.Spec {
128155 Kind : "nvidia.com/gpu" ,
156+ Devices : []specs.Device {
157+ {
158+ Name : "one" ,
159+ ContainerEdits : specs.ContainerEdits {
160+ Env : []string {"DEVICE_FOO=bar" },
161+ },
162+ },
163+ },
129164 ContainerEdits : specs.ContainerEdits {
130- Env : []string {"FOO=bar" },
131165 DeviceNodes : []* specs.DeviceNode {
132166 {
133167 HostPath : "/some/dev/dev0" ,
@@ -147,14 +181,16 @@ kind: nvidia.com/gpu
147181 ),
148182 expectedSpec : `---
149183cdiVersion: 0.5.0
184+ kind: nvidia.com/gpu
185+ devices:
186+ - name: one
187+ containerEdits:
188+ env:
189+ - DEVICE_FOO=bar
150190containerEdits:
151191 deviceNodes:
152- - hostPath: /dev/dev0
153- path: /dev/dev0
154- env:
155- - FOO=bar
156- devices: null
157- kind: nvidia.com/gpu
192+ - path: /dev/dev0
193+ hostPath: /dev/dev0
158194` ,
159195 },
160196 }
0 commit comments