@@ -244,3 +244,165 @@ func TestHasDynamicParameterUpdate(t *testing.T) {
244244 })
245245 }
246246}
247+
248+ func TestValidateConfigPatch (t * testing.T ) {
249+ configs := []parametersv1alpha1.ComponentConfigDescription {{
250+ Name : "mysql.cnf" ,
251+ FileFormatConfig : & parametersv1alpha1.FileFormatConfig {
252+ Format : parametersv1alpha1 .Ini ,
253+ FormatterAction : parametersv1alpha1.FormatterAction {
254+ IniConfig : & parametersv1alpha1.IniConfig {SectionName : "mysqld" },
255+ },
256+ },
257+ }}
258+
259+ require .NoError (t , ValidateConfigPatch (& ConfigPatchInfo {}, configs ))
260+ require .NoError (t , ValidateConfigPatch (& ConfigPatchInfo {
261+ IsModify : true ,
262+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":"200"}}` )},
263+ }, configs ))
264+
265+ err := ValidateConfigPatch (& ConfigPatchInfo {
266+ IsModify : true ,
267+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":null}}` )},
268+ }, configs )
269+ require .ErrorContains (t , err , "delete config parameter [max_connections] is not support" )
270+ }
271+
272+ func TestIsUpdateDynamicParameters (t * testing.T ) {
273+ config := & parametersv1alpha1.FileFormatConfig {
274+ Format : parametersv1alpha1 .Ini ,
275+ FormatterAction : parametersv1alpha1.FormatterAction {
276+ IniConfig : & parametersv1alpha1.IniConfig {SectionName : "mysqld" },
277+ },
278+ }
279+
280+ tests := []struct {
281+ name string
282+ def * parametersv1alpha1.ParametersDefinitionSpec
283+ patch * ConfigPatchInfo
284+ want bool
285+ wantErr bool
286+ }{
287+ {
288+ name : "delete config requires restart" ,
289+ def : & parametersv1alpha1.ParametersDefinitionSpec {},
290+ patch : & ConfigPatchInfo {
291+ DeleteConfig : map [string ]interface {}{"mysql.cnf" : map [string ]interface {}{"max_connections" : "200" }},
292+ },
293+ want : false ,
294+ },
295+ {
296+ name : "empty update is dynamic" ,
297+ def : & parametersv1alpha1.ParametersDefinitionSpec {},
298+ patch : & ConfigPatchInfo {},
299+ want : true ,
300+ },
301+ {
302+ name : "invalid update patch" ,
303+ def : & parametersv1alpha1.ParametersDefinitionSpec {},
304+ patch : & ConfigPatchInfo {
305+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{` )},
306+ },
307+ wantErr : true ,
308+ },
309+ {
310+ name : "dynamic parameter only" ,
311+ def : & parametersv1alpha1.ParametersDefinitionSpec {
312+ DynamicParameters : []string {"max_connections" },
313+ },
314+ patch : & ConfigPatchInfo {
315+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":"200"}}` )},
316+ },
317+ want : true ,
318+ },
319+ {
320+ name : "static parameter is not dynamic" ,
321+ def : & parametersv1alpha1.ParametersDefinitionSpec {
322+ StaticParameters : []string {"max_connections" },
323+ },
324+ patch : & ConfigPatchInfo {
325+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":"200"}}` )},
326+ },
327+ want : false ,
328+ },
329+ {
330+ name : "unknown parameter with dynamic list is not dynamic" ,
331+ def : & parametersv1alpha1.ParametersDefinitionSpec {
332+ DynamicParameters : []string {"innodb_buffer_pool_size" },
333+ },
334+ patch : & ConfigPatchInfo {
335+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":"200"}}` )},
336+ },
337+ want : false ,
338+ },
339+ {
340+ name : "static list without dynamic list defaults to reload for non-static update" ,
341+ def : & parametersv1alpha1.ParametersDefinitionSpec {
342+ StaticParameters : []string {"innodb_buffer_pool_size" },
343+ },
344+ patch : & ConfigPatchInfo {
345+ UpdateConfig : map [string ][]byte {"mysql.cnf" : []byte (`{"mysqld":{"max_connections":"200"}}` )},
346+ },
347+ want : true ,
348+ },
349+ }
350+
351+ for _ , tt := range tests {
352+ t .Run (tt .name , func (t * testing.T ) {
353+ got , err := IsUpdateDynamicParameters (config , tt .def , tt .patch )
354+ if tt .wantErr {
355+ require .Error (t , err )
356+ return
357+ }
358+ require .NoError (t , err )
359+ require .Equal (t , tt .want , got )
360+ })
361+ }
362+ }
363+
364+ func TestCheckUpdateDynamicParameters (t * testing.T ) {
365+ config := & parametersv1alpha1.FileFormatConfig {
366+ Format : parametersv1alpha1 .Ini ,
367+ FormatterAction : parametersv1alpha1.FormatterAction {
368+ IniConfig : & parametersv1alpha1.IniConfig {SectionName : "mysqld" },
369+ },
370+ }
371+
372+ tests := []struct {
373+ name string
374+ def * parametersv1alpha1.ParametersDefinitionSpec
375+ patch string
376+ want bool
377+ wantErr bool
378+ }{
379+ {name : "empty patch" , def : & parametersv1alpha1.ParametersDefinitionSpec {}, want : true },
380+ {name : "invalid patch" , def : & parametersv1alpha1.ParametersDefinitionSpec {}, patch : `{` , wantErr : true },
381+ {
382+ name : "dynamic parameter" ,
383+ def : & parametersv1alpha1.ParametersDefinitionSpec {
384+ DynamicParameters : []string {"max_connections" },
385+ },
386+ patch : `{"mysqld":{"max_connections":"200"}}` ,
387+ want : true ,
388+ },
389+ {
390+ name : "no parameter lists defaults to restart" ,
391+ def : & parametersv1alpha1.ParametersDefinitionSpec {},
392+ patch : `{"mysqld":{"max_connections":"200"}}` ,
393+ want : false ,
394+ },
395+ }
396+
397+ for _ , tt := range tests {
398+ t .Run (tt .name , func (t * testing.T ) {
399+ got , err := CheckUpdateDynamicParameters (config , tt .def , tt .patch )
400+ if tt .wantErr {
401+ require .Error (t , err )
402+ return
403+ }
404+ require .NoError (t , err )
405+ require .Equal (t , tt .want , got )
406+ })
407+ }
408+ }
0 commit comments