@@ -28,37 +28,40 @@ import (
28
28
29
29
func TestValidateConfig (t * testing.T ) {
30
30
for desc , test := range map [string ]struct {
31
- config * PluginConfig
32
- expectedErr string
33
- expected * PluginConfig
34
- imageConfig * ImageConfig
35
- imageExpectedErr string
36
- imageExpected * ImageConfig
37
- warnings []deprecation.Warning
31
+ runtimeConfig * RuntimeConfig
32
+ runtimeExpectedErr string
33
+ runtimeExpected * RuntimeConfig
34
+ imageConfig * ImageConfig
35
+ imageExpectedErr string
36
+ imageExpected * ImageConfig
37
+ serverConfig * ServerConfig
38
+ serverExpectedErr string
39
+ serverExpected * ServerConfig
40
+ warnings []deprecation.Warning
38
41
}{
39
42
"no default_runtime_name" : {
40
- config : & PluginConfig {},
41
- expectedErr : "`default_runtime_name` is empty" ,
43
+ runtimeConfig : & RuntimeConfig {},
44
+ runtimeExpectedErr : "`default_runtime_name` is empty" ,
42
45
},
43
46
"no runtime[default_runtime_name]" : {
44
- config : & PluginConfig {
47
+ runtimeConfig : & RuntimeConfig {
45
48
ContainerdConfig : ContainerdConfig {
46
49
DefaultRuntimeName : RuntimeDefault ,
47
50
},
48
51
},
49
- expectedErr : "no corresponding runtime configured in `containerd.runtimes` for `containerd` `default_runtime_name = \" default\" " ,
52
+ runtimeExpectedErr : "no corresponding runtime configured in `containerd.runtimes` for `containerd` `default_runtime_name = \" default\" " ,
50
53
},
51
54
52
55
"deprecated auths" : {
53
- config : & PluginConfig {
56
+ runtimeConfig : & RuntimeConfig {
54
57
ContainerdConfig : ContainerdConfig {
55
58
DefaultRuntimeName : RuntimeDefault ,
56
59
Runtimes : map [string ]Runtime {
57
60
RuntimeDefault : {},
58
61
},
59
62
},
60
63
},
61
- expected : & PluginConfig {
64
+ runtimeExpected : & RuntimeConfig {
62
65
ContainerdConfig : ContainerdConfig {
63
66
DefaultRuntimeName : RuntimeDefault ,
64
67
Runtimes : map [string ]Runtime {
@@ -92,18 +95,10 @@ func TestValidateConfig(t *testing.T) {
92
95
warnings : []deprecation.Warning {deprecation .CRIRegistryAuths },
93
96
},
94
97
"invalid stream_idle_timeout" : {
95
- config : & PluginConfig {
98
+ serverConfig : & ServerConfig {
96
99
StreamIdleTimeout : "invalid" ,
97
- ContainerdConfig : ContainerdConfig {
98
- DefaultRuntimeName : RuntimeDefault ,
99
- Runtimes : map [string ]Runtime {
100
- RuntimeDefault : {
101
- Type : "default" ,
102
- },
103
- },
104
- },
105
100
},
106
- expectedErr : "invalid stream idle timeout" ,
101
+ serverExpectedErr : "invalid stream idle timeout" ,
107
102
},
108
103
"conflicting mirror registry config" : {
109
104
imageConfig : & ImageConfig {
@@ -117,7 +112,7 @@ func TestValidateConfig(t *testing.T) {
117
112
imageExpectedErr : "`mirrors` cannot be set when `config_path` is provided" ,
118
113
},
119
114
"deprecated mirrors" : {
120
- config : & PluginConfig {
115
+ runtimeConfig : & RuntimeConfig {
121
116
ContainerdConfig : ContainerdConfig {
122
117
DefaultRuntimeName : RuntimeDefault ,
123
118
Runtimes : map [string ]Runtime {
@@ -132,7 +127,7 @@ func TestValidateConfig(t *testing.T) {
132
127
},
133
128
},
134
129
},
135
- expected : & PluginConfig {
130
+ runtimeExpected : & RuntimeConfig {
136
131
ContainerdConfig : ContainerdConfig {
137
132
DefaultRuntimeName : RuntimeDefault ,
138
133
Runtimes : map [string ]Runtime {
@@ -152,7 +147,7 @@ func TestValidateConfig(t *testing.T) {
152
147
warnings : []deprecation.Warning {deprecation .CRIRegistryMirrors },
153
148
},
154
149
"deprecated configs" : {
155
- config : & PluginConfig {
150
+ runtimeConfig : & RuntimeConfig {
156
151
ContainerdConfig : ContainerdConfig {
157
152
DefaultRuntimeName : RuntimeDefault ,
158
153
Runtimes : map [string ]Runtime {
@@ -171,7 +166,7 @@ func TestValidateConfig(t *testing.T) {
171
166
},
172
167
},
173
168
},
174
- expected : & PluginConfig {
169
+ runtimeExpected : & RuntimeConfig {
175
170
ContainerdConfig : ContainerdConfig {
176
171
DefaultRuntimeName : RuntimeDefault ,
177
172
Runtimes : map [string ]Runtime {
@@ -195,7 +190,7 @@ func TestValidateConfig(t *testing.T) {
195
190
warnings : []deprecation.Warning {deprecation .CRIRegistryConfigs },
196
191
},
197
192
"privileged_without_host_devices_all_devices_allowed without privileged_without_host_devices" : {
198
- config : & PluginConfig {
193
+ runtimeConfig : & RuntimeConfig {
199
194
ContainerdConfig : ContainerdConfig {
200
195
DefaultRuntimeName : RuntimeDefault ,
201
196
Runtimes : map [string ]Runtime {
@@ -207,10 +202,10 @@ func TestValidateConfig(t *testing.T) {
207
202
},
208
203
},
209
204
},
210
- expectedErr : "`privileged_without_host_devices_all_devices_allowed` requires `privileged_without_host_devices` to be enabled" ,
205
+ runtimeExpectedErr : "`privileged_without_host_devices_all_devices_allowed` requires `privileged_without_host_devices` to be enabled" ,
211
206
},
212
207
"invalid drain_exec_sync_io_timeout input" : {
213
- config : & PluginConfig {
208
+ runtimeConfig : & RuntimeConfig {
214
209
ContainerdConfig : ContainerdConfig {
215
210
DefaultRuntimeName : RuntimeDefault ,
216
211
Runtimes : map [string ]Runtime {
@@ -221,18 +216,18 @@ func TestValidateConfig(t *testing.T) {
221
216
},
222
217
DrainExecSyncIOTimeout : "10" ,
223
218
},
224
- expectedErr : "invalid `drain_exec_sync_io_timeout`" ,
219
+ runtimeExpectedErr : "invalid `drain_exec_sync_io_timeout`" ,
225
220
},
226
221
} {
227
222
t .Run (desc , func (t * testing.T ) {
228
223
var warnings []deprecation.Warning
229
- if test .config != nil {
230
- w , err := ValidatePluginConfig (context .Background (), test .config )
231
- if test .expectedErr != "" {
232
- assert .Contains (t , err .Error (), test .expectedErr )
224
+ if test .runtimeConfig != nil {
225
+ w , err := ValidateRuntimeConfig (context .Background (), test .runtimeConfig )
226
+ if test .runtimeExpectedErr != "" {
227
+ assert .Contains (t , err .Error (), test .runtimeExpectedErr )
233
228
} else {
234
229
assert .NoError (t , err )
235
- assert .Equal (t , test .expected , test .config )
230
+ assert .Equal (t , test .runtimeExpected , test .runtimeConfig )
236
231
}
237
232
warnings = append (warnings , w ... )
238
233
}
@@ -246,6 +241,16 @@ func TestValidateConfig(t *testing.T) {
246
241
}
247
242
warnings = append (warnings , w ... )
248
243
}
244
+ if test .serverConfig != nil {
245
+ w , err := ValidateServerConfig (context .Background (), test .serverConfig )
246
+ if test .serverExpectedErr != "" {
247
+ assert .Contains (t , err .Error (), test .serverExpectedErr )
248
+ } else {
249
+ assert .NoError (t , err )
250
+ assert .Equal (t , test .serverExpected , test .serverConfig )
251
+ }
252
+ warnings = append (warnings , w ... )
253
+ }
249
254
250
255
if len (test .warnings ) > 0 {
251
256
assert .ElementsMatch (t , test .warnings , warnings )
0 commit comments