@@ -21,6 +21,7 @@ import (
21
21
"testing"
22
22
23
23
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/engine/containerd"
24
+ "github.com/NVIDIA/nvidia-container-toolkit/tools/container"
24
25
"github.com/pelletier/go-toml"
25
26
"github.com/stretchr/testify/require"
26
27
)
@@ -31,7 +32,7 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
31
32
testCases := []struct {
32
33
legacyConfig bool
33
34
setAsDefault bool
34
- runtimeClass string
35
+ runtimeName string
35
36
expectedDefaultRuntimeName interface {}
36
37
expectedDefaultRuntimeBinary interface {}
37
38
}{
@@ -51,14 +52,14 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
51
52
{
52
53
legacyConfig : true ,
53
54
setAsDefault : true ,
54
- runtimeClass : "NAME" ,
55
+ runtimeName : "NAME" ,
55
56
expectedDefaultRuntimeName : nil ,
56
57
expectedDefaultRuntimeBinary : "/test/runtime/dir/nvidia-container-runtime" ,
57
58
},
58
59
{
59
60
legacyConfig : true ,
60
61
setAsDefault : true ,
61
- runtimeClass : "nvidia-experimental" ,
62
+ runtimeName : "nvidia-experimental" ,
62
63
expectedDefaultRuntimeName : nil ,
63
64
expectedDefaultRuntimeBinary : "/test/runtime/dir/nvidia-container-runtime.experimental" ,
64
65
},
@@ -77,14 +78,14 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
77
78
{
78
79
legacyConfig : false ,
79
80
setAsDefault : true ,
80
- runtimeClass : "NAME" ,
81
+ runtimeName : "NAME" ,
81
82
expectedDefaultRuntimeName : "NAME" ,
82
83
expectedDefaultRuntimeBinary : nil ,
83
84
},
84
85
{
85
86
legacyConfig : false ,
86
87
setAsDefault : true ,
87
- runtimeClass : "nvidia-experimental" ,
88
+ runtimeName : "nvidia-experimental" ,
88
89
expectedDefaultRuntimeName : "nvidia-experimental" ,
89
90
expectedDefaultRuntimeBinary : nil ,
90
91
},
@@ -93,11 +94,13 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
93
94
for i , tc := range testCases {
94
95
t .Run (fmt .Sprintf ("%d" , i ), func (t * testing.T ) {
95
96
o := & options {
96
- useLegacyConfig : tc .legacyConfig ,
97
- setAsDefault : tc .setAsDefault ,
98
- runtimeClass : tc .runtimeClass ,
97
+ Options : container.Options {
98
+ RuntimeName : tc .runtimeName ,
99
+ RuntimeDir : runtimeDir ,
100
+ SetAsDefault : tc .setAsDefault ,
101
+ },
99
102
runtimeType : runtimeType ,
100
- runtimeDir : runtimeDir ,
103
+ useLegacyConfig : tc . legacyConfig ,
101
104
}
102
105
103
106
config , err := toml .TreeFromMap (map [string ]interface {}{})
@@ -109,7 +112,7 @@ func TestUpdateV1ConfigDefaultRuntime(t *testing.T) {
109
112
RuntimeType : runtimeType ,
110
113
}
111
114
112
- err = UpdateConfig (v1 , o )
115
+ err = o . UpdateConfig (v1 )
113
116
require .NoError (t , err , "%d: %v" , i , tc )
114
117
115
118
defaultRuntimeName := v1 .GetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime_name" })
@@ -138,11 +141,11 @@ func TestUpdateV1Config(t *testing.T) {
138
141
const runtimeDir = "/test/runtime/dir"
139
142
140
143
testCases := []struct {
141
- runtimeClass string
144
+ runtimeName string
142
145
expectedConfig map [string ]interface {}
143
146
}{
144
147
{
145
- runtimeClass : "nvidia" ,
148
+ runtimeName : "nvidia" ,
146
149
expectedConfig : map [string ]interface {}{
147
150
"version" : int64 (1 ),
148
151
"plugins" : map [string ]interface {}{
@@ -200,7 +203,7 @@ func TestUpdateV1Config(t *testing.T) {
200
203
},
201
204
},
202
205
{
203
- runtimeClass : "NAME" ,
206
+ runtimeName : "NAME" ,
204
207
expectedConfig : map [string ]interface {}{
205
208
"version" : int64 (1 ),
206
209
"plugins" : map [string ]interface {}{
@@ -258,7 +261,7 @@ func TestUpdateV1Config(t *testing.T) {
258
261
},
259
262
},
260
263
{
261
- runtimeClass : "nvidia-experimental" ,
264
+ runtimeName : "nvidia-experimental" ,
262
265
expectedConfig : map [string ]interface {}{
263
266
"version" : int64 (1 ),
264
267
"plugins" : map [string ]interface {}{
@@ -320,9 +323,10 @@ func TestUpdateV1Config(t *testing.T) {
320
323
for i , tc := range testCases {
321
324
t .Run (fmt .Sprintf ("%d" , i ), func (t * testing.T ) {
322
325
o := & options {
323
- runtimeClass : tc .runtimeClass ,
324
- runtimeType : runtimeType ,
325
- runtimeDir : runtimeDir ,
326
+ Options : container.Options {
327
+ RuntimeName : tc .runtimeName ,
328
+ RuntimeDir : runtimeDir ,
329
+ },
326
330
}
327
331
328
332
config , err := toml .TreeFromMap (map [string ]interface {}{})
@@ -335,7 +339,7 @@ func TestUpdateV1Config(t *testing.T) {
335
339
ContainerAnnotations : []string {"cdi.k8s.io/*" },
336
340
}
337
341
338
- err = UpdateConfig (v1 , o )
342
+ err = o . UpdateConfig (v1 )
339
343
require .NoError (t , err )
340
344
341
345
expected , err := toml .TreeFromMap (tc .expectedConfig )
@@ -350,11 +354,11 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
350
354
const runtimeDir = "/test/runtime/dir"
351
355
352
356
testCases := []struct {
353
- runtimeClass string
357
+ runtimeName string
354
358
expectedConfig map [string ]interface {}
355
359
}{
356
360
{
357
- runtimeClass : "nvidia" ,
361
+ runtimeName : "nvidia" ,
358
362
expectedConfig : map [string ]interface {}{
359
363
"version" : int64 (1 ),
360
364
"plugins" : map [string ]interface {}{
@@ -426,7 +430,7 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
426
430
},
427
431
},
428
432
{
429
- runtimeClass : "NAME" ,
433
+ runtimeName : "NAME" ,
430
434
expectedConfig : map [string ]interface {}{
431
435
"version" : int64 (1 ),
432
436
"plugins" : map [string ]interface {}{
@@ -498,7 +502,7 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
498
502
},
499
503
},
500
504
{
501
- runtimeClass : "nvidia-experimental" ,
505
+ runtimeName : "nvidia-experimental" ,
502
506
expectedConfig : map [string ]interface {}{
503
507
"version" : int64 (1 ),
504
508
"plugins" : map [string ]interface {}{
@@ -574,9 +578,10 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
574
578
for i , tc := range testCases {
575
579
t .Run (fmt .Sprintf ("%d" , i ), func (t * testing.T ) {
576
580
o := & options {
577
- runtimeClass : tc .runtimeClass ,
578
- runtimeType : runtimeType ,
579
- runtimeDir : runtimeDir ,
581
+ Options : container.Options {
582
+ RuntimeName : tc .runtimeName ,
583
+ RuntimeDir : runtimeDir ,
584
+ },
580
585
}
581
586
582
587
config , err := toml .TreeFromMap (runcConfigMapV1 ("/runc-binary" ))
@@ -589,7 +594,7 @@ func TestUpdateV1ConfigWithRuncPresent(t *testing.T) {
589
594
ContainerAnnotations : []string {"cdi.k8s.io/*" },
590
595
}
591
596
592
- err = UpdateConfig (v1 , o )
597
+ err = o . UpdateConfig (v1 )
593
598
require .NoError (t , err )
594
599
595
600
expected , err := toml .TreeFromMap (tc .expectedConfig )
@@ -653,7 +658,9 @@ func TestRevertV1Config(t *testing.T) {
653
658
for i , tc := range testCases {
654
659
t .Run (fmt .Sprintf ("%d" , i ), func (t * testing.T ) {
655
660
o := & options {
656
- runtimeClass : "nvidia" ,
661
+ Options : container.Options {
662
+ RuntimeName : "nvidia" ,
663
+ },
657
664
}
658
665
659
666
config , err := toml .TreeFromMap (tc .config )
@@ -668,7 +675,7 @@ func TestRevertV1Config(t *testing.T) {
668
675
RuntimeType : runtimeType ,
669
676
}
670
677
671
- err = RevertConfig (v1 , o )
678
+ err = o . RevertConfig (v1 )
672
679
require .NoError (t , err , "%d: %v" , i , tc )
673
680
674
681
configContents , _ := toml .Marshal (config )
0 commit comments