@@ -19,152 +19,109 @@ package config
1919import (
2020 "testing"
2121
22- "github.com/NVIDIA/nvidia-container-toolkit/internal/config"
23- "github.com/pelletier/go-toml"
2422 "github.com/stretchr/testify/require"
2523)
2624
2725func TestSetFlagToKeyValue (t * testing.T ) {
26+ // TODO: We need to enable this test again since switching to reflect.
2827 testCases := []struct {
2928 description string
30- config map [string ]interface {}
3129 setFlag string
3230 expectedKey string
3331 expectedValue interface {}
3432 expectedError error
3533 }{
3634 {
37- description : "empty config returns an error" ,
38- setFlag : "anykey= value" ,
39- expectedKey : "anykey " ,
35+ description : "option not present returns an error" ,
36+ setFlag : "undefined=new- value" ,
37+ expectedKey : "undefined " ,
4038 expectedError : errInvalidConfigOption ,
4139 },
4240 {
43- description : "option not present returns an error" ,
44- config : map [string ]interface {}{
45- "defined" : "defined-value" ,
46- },
47- setFlag : "undefined=new-value" ,
48- expectedKey : "undefined" ,
41+ description : "undefined nexted option returns error" ,
42+ setFlag : "nvidia-container-cli.undefined" ,
43+ expectedKey : "nvidia-container-cli.undefined" ,
4944 expectedError : errInvalidConfigOption ,
5045 },
5146 {
52- description : "boolean option assumes true" ,
53- config : map [string ]interface {}{
54- "boolean" : false ,
55- },
56- setFlag : "boolean" ,
57- expectedKey : "boolean" ,
47+ description : "boolean option assumes true" ,
48+ setFlag : "disable-require" ,
49+ expectedKey : "disable-require" ,
5850 expectedValue : true ,
5951 },
6052 {
61- description : "boolean option returns true" ,
62- config : map [string ]interface {}{
63- "boolean" : false ,
64- },
65- setFlag : "boolean=true" ,
66- expectedKey : "boolean" ,
53+ description : "boolean option returns true" ,
54+ setFlag : "disable-require=true" ,
55+ expectedKey : "disable-require" ,
6756 expectedValue : true ,
6857 },
6958 {
70- description : "boolean option returns false" ,
71- config : map [string ]interface {}{
72- "boolean" : false ,
73- },
74- setFlag : "boolean=false" ,
75- expectedKey : "boolean" ,
59+ description : "boolean option returns false" ,
60+ setFlag : "disable-require=false" ,
61+ expectedKey : "disable-require" ,
7662 expectedValue : false ,
7763 },
7864 {
79- description : "invalid boolean option returns error" ,
80- config : map [string ]interface {}{
81- "boolean" : false ,
82- },
83- setFlag : "boolean=something" ,
84- expectedKey : "boolean" ,
65+ description : "invalid boolean option returns error" ,
66+ setFlag : "disable-require=something" ,
67+ expectedKey : "disable-require" ,
8568 expectedValue : "something" ,
8669 expectedError : errInvalidFormat ,
8770 },
8871 {
89- description : "string option requires value" ,
90- config : map [string ]interface {}{
91- "string" : "value" ,
92- },
93- setFlag : "string" ,
94- expectedKey : "string" ,
72+ description : "string option requires value" ,
73+ setFlag : "swarm-resource" ,
74+ expectedKey : "swarm-resource" ,
9575 expectedValue : nil ,
9676 expectedError : errInvalidFormat ,
9777 },
9878 {
99- description : "string option returns value" ,
100- config : map [string ]interface {}{
101- "string" : "value" ,
102- },
103- setFlag : "string=string-value" ,
104- expectedKey : "string" ,
79+ description : "string option returns value" ,
80+ setFlag : "swarm-resource=string-value" ,
81+ expectedKey : "swarm-resource" ,
10582 expectedValue : "string-value" ,
10683 },
10784 {
108- description : "string option returns value with equals" ,
109- config : map [string ]interface {}{
110- "string" : "value" ,
111- },
112- setFlag : "string=string-value=more" ,
113- expectedKey : "string" ,
85+ description : "string option returns value with equals" ,
86+ setFlag : "swarm-resource=string-value=more" ,
87+ expectedKey : "swarm-resource" ,
11488 expectedValue : "string-value=more" ,
11589 },
11690 {
117- description : "string option treats bool value as string" ,
118- config : map [string ]interface {}{
119- "string" : "value" ,
120- },
121- setFlag : "string=true" ,
122- expectedKey : "string" ,
91+ description : "string option treats bool value as string" ,
92+ setFlag : "swarm-resource=true" ,
93+ expectedKey : "swarm-resource" ,
12394 expectedValue : "true" ,
12495 },
12596 {
126- description : "string option treats int value as string" ,
127- config : map [string ]interface {}{
128- "string" : "value" ,
129- },
130- setFlag : "string=5" ,
131- expectedKey : "string" ,
97+ description : "string option treats int value as string" ,
98+ setFlag : "swarm-resource=5" ,
99+ expectedKey : "swarm-resource" ,
132100 expectedValue : "5" ,
133101 },
134102 {
135- description : "[]string option returns single value" ,
136- config : map [string ]interface {}{
137- "string" : []string {"value" },
138- },
139- setFlag : "string=string-value" ,
140- expectedKey : "string" ,
103+ description : "[]string option returns single value" ,
104+ setFlag : "nvidia-container-cli.environment=string-value" ,
105+ expectedKey : "nvidia-container-cli.environment" ,
141106 expectedValue : []string {"string-value" },
142107 },
143108 {
144- description : "[]string option returns multiple values" ,
145- config : map [string ]interface {}{
146- "string" : []string {"value" },
147- },
148- setFlag : "string=first,second" ,
149- expectedKey : "string" ,
109+ description : "[]string option returns multiple values" ,
110+ setFlag : "nvidia-container-cli.environment=first,second" ,
111+ expectedKey : "nvidia-container-cli.environment" ,
150112 expectedValue : []string {"first" , "second" },
151113 },
152114 {
153- description : "[]string option returns values with equals" ,
154- config : map [string ]interface {}{
155- "string" : []string {"value" },
156- },
157- setFlag : "string=first=1,second=2" ,
158- expectedKey : "string" ,
115+ description : "[]string option returns values with equals" ,
116+ setFlag : "nvidia-container-cli.environment=first=1,second=2" ,
117+ expectedKey : "nvidia-container-cli.environment" ,
159118 expectedValue : []string {"first=1" , "second=2" },
160119 },
161120 }
162121
163122 for _ , tc := range testCases {
164123 t .Run (tc .description , func (t * testing.T ) {
165- tree , _ := toml .TreeFromMap (tc .config )
166- cfgToml := (* config .Toml )(tree )
167- k , v , err := (* configToml )(cfgToml ).setFlagToKeyValue (tc .setFlag )
124+ k , v , err := setFlagToKeyValue (tc .setFlag )
168125 require .ErrorIs (t , err , tc .expectedError )
169126 require .EqualValues (t , tc .expectedKey , k )
170127 require .EqualValues (t , tc .expectedValue , v )
0 commit comments