@@ -28,37 +28,40 @@ import (
2828
2929func TestValidateConfig (t * testing.T ) {
3030 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
3841 }{
3942 "no default_runtime_name" : {
40- config : & PluginConfig {},
41- expectedErr : "`default_runtime_name` is empty" ,
43+ runtimeConfig : & RuntimeConfig {},
44+ runtimeExpectedErr : "`default_runtime_name` is empty" ,
4245 },
4346 "no runtime[default_runtime_name]" : {
44- config : & PluginConfig {
47+ runtimeConfig : & RuntimeConfig {
4548 ContainerdConfig : ContainerdConfig {
4649 DefaultRuntimeName : RuntimeDefault ,
4750 },
4851 },
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\" " ,
5053 },
5154
5255 "deprecated auths" : {
53- config : & PluginConfig {
56+ runtimeConfig : & RuntimeConfig {
5457 ContainerdConfig : ContainerdConfig {
5558 DefaultRuntimeName : RuntimeDefault ,
5659 Runtimes : map [string ]Runtime {
5760 RuntimeDefault : {},
5861 },
5962 },
6063 },
61- expected : & PluginConfig {
64+ runtimeExpected : & RuntimeConfig {
6265 ContainerdConfig : ContainerdConfig {
6366 DefaultRuntimeName : RuntimeDefault ,
6467 Runtimes : map [string ]Runtime {
@@ -92,18 +95,10 @@ func TestValidateConfig(t *testing.T) {
9295 warnings : []deprecation.Warning {deprecation .CRIRegistryAuths },
9396 },
9497 "invalid stream_idle_timeout" : {
95- config : & PluginConfig {
98+ serverConfig : & ServerConfig {
9699 StreamIdleTimeout : "invalid" ,
97- ContainerdConfig : ContainerdConfig {
98- DefaultRuntimeName : RuntimeDefault ,
99- Runtimes : map [string ]Runtime {
100- RuntimeDefault : {
101- Type : "default" ,
102- },
103- },
104- },
105100 },
106- expectedErr : "invalid stream idle timeout" ,
101+ serverExpectedErr : "invalid stream idle timeout" ,
107102 },
108103 "conflicting mirror registry config" : {
109104 imageConfig : & ImageConfig {
@@ -117,7 +112,7 @@ func TestValidateConfig(t *testing.T) {
117112 imageExpectedErr : "`mirrors` cannot be set when `config_path` is provided" ,
118113 },
119114 "deprecated mirrors" : {
120- config : & PluginConfig {
115+ runtimeConfig : & RuntimeConfig {
121116 ContainerdConfig : ContainerdConfig {
122117 DefaultRuntimeName : RuntimeDefault ,
123118 Runtimes : map [string ]Runtime {
@@ -132,7 +127,7 @@ func TestValidateConfig(t *testing.T) {
132127 },
133128 },
134129 },
135- expected : & PluginConfig {
130+ runtimeExpected : & RuntimeConfig {
136131 ContainerdConfig : ContainerdConfig {
137132 DefaultRuntimeName : RuntimeDefault ,
138133 Runtimes : map [string ]Runtime {
@@ -152,7 +147,7 @@ func TestValidateConfig(t *testing.T) {
152147 warnings : []deprecation.Warning {deprecation .CRIRegistryMirrors },
153148 },
154149 "deprecated configs" : {
155- config : & PluginConfig {
150+ runtimeConfig : & RuntimeConfig {
156151 ContainerdConfig : ContainerdConfig {
157152 DefaultRuntimeName : RuntimeDefault ,
158153 Runtimes : map [string ]Runtime {
@@ -171,7 +166,7 @@ func TestValidateConfig(t *testing.T) {
171166 },
172167 },
173168 },
174- expected : & PluginConfig {
169+ runtimeExpected : & RuntimeConfig {
175170 ContainerdConfig : ContainerdConfig {
176171 DefaultRuntimeName : RuntimeDefault ,
177172 Runtimes : map [string ]Runtime {
@@ -195,7 +190,7 @@ func TestValidateConfig(t *testing.T) {
195190 warnings : []deprecation.Warning {deprecation .CRIRegistryConfigs },
196191 },
197192 "privileged_without_host_devices_all_devices_allowed without privileged_without_host_devices" : {
198- config : & PluginConfig {
193+ runtimeConfig : & RuntimeConfig {
199194 ContainerdConfig : ContainerdConfig {
200195 DefaultRuntimeName : RuntimeDefault ,
201196 Runtimes : map [string ]Runtime {
@@ -207,10 +202,10 @@ func TestValidateConfig(t *testing.T) {
207202 },
208203 },
209204 },
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" ,
211206 },
212207 "invalid drain_exec_sync_io_timeout input" : {
213- config : & PluginConfig {
208+ runtimeConfig : & RuntimeConfig {
214209 ContainerdConfig : ContainerdConfig {
215210 DefaultRuntimeName : RuntimeDefault ,
216211 Runtimes : map [string ]Runtime {
@@ -221,18 +216,18 @@ func TestValidateConfig(t *testing.T) {
221216 },
222217 DrainExecSyncIOTimeout : "10" ,
223218 },
224- expectedErr : "invalid `drain_exec_sync_io_timeout`" ,
219+ runtimeExpectedErr : "invalid `drain_exec_sync_io_timeout`" ,
225220 },
226221 } {
227222 t .Run (desc , func (t * testing.T ) {
228223 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 )
233228 } else {
234229 assert .NoError (t , err )
235- assert .Equal (t , test .expected , test .config )
230+ assert .Equal (t , test .runtimeExpected , test .runtimeConfig )
236231 }
237232 warnings = append (warnings , w ... )
238233 }
@@ -246,6 +241,16 @@ func TestValidateConfig(t *testing.T) {
246241 }
247242 warnings = append (warnings , w ... )
248243 }
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+ }
249254
250255 if len (test .warnings ) > 0 {
251256 assert .ElementsMatch (t , test .warnings , warnings )
0 commit comments