@@ -3026,3 +3026,64 @@ batch-keys = 512`,
30263026 testFn (& tests [i ], t )
30273027 }
30283028}
3029+
3030+ func TestApplyOverlay (t * testing.T ) {
3031+ g := NewGomegaWithT (t )
3032+
3033+ tests := []struct {
3034+ name string
3035+ configFile string
3036+ configFileOverlay string
3037+ key string
3038+ value interface {}
3039+ }{
3040+ {
3041+ name : "empty config-file with empty overlay" ,
3042+ configFile : "" ,
3043+ configFileOverlay : "" ,
3044+ key : "gc.ratio-threshold" ,
3045+ value : - 1.0 ,
3046+ },
3047+ {
3048+ name : "existing config-file with overlay" ,
3049+ configFile : "[log]\n level = \" info\" \n " ,
3050+ configFileOverlay : "" ,
3051+ key : "gc.ratio-threshold" ,
3052+ value : - 1.0 ,
3053+ },
3054+ {
3055+ name : "empty config-file with existing overlay" ,
3056+ configFile : "" ,
3057+ configFileOverlay : "[storage.block-cache]\n capacity = \" 1GB\" \n " ,
3058+ key : "gc.ratio-threshold" ,
3059+ value : - 1.0 ,
3060+ },
3061+ }
3062+
3063+ for _ , tt := range tests {
3064+ t .Run (tt .name , func (t * testing.T ) {
3065+ cm := & corev1.ConfigMap {
3066+ Data : map [string ]string {
3067+ "config-file" : tt .configFile ,
3068+ "config-file-overlay" : tt .configFileOverlay ,
3069+ },
3070+ }
3071+
3072+ err := applyOverlay (cm , tt .key , tt .value )
3073+ g .Expect (err ).NotTo (HaveOccurred ())
3074+
3075+ // Check that config-file now contains the merged configuration
3076+ g .Expect (cm .Data ["config-file" ]).NotTo (BeEmpty (), "config-file should not be empty after applying overlay" )
3077+
3078+ // Parse the result to verify it contains our key
3079+ wrapper := v1alpha1 .NewTiKVConfig ()
3080+ err = wrapper .UnmarshalTOML ([]byte (cm .Data ["config-file" ]))
3081+ g .Expect (err ).NotTo (HaveOccurred ())
3082+
3083+ // Verify the key was set correctly
3084+ val := wrapper .Get (tt .key )
3085+ g .Expect (val ).NotTo (BeNil (), "expected key %s should be present in config" , tt .key )
3086+ g .Expect (val .Interface ()).To (Equal (tt .value ), "expected value for key %s" , tt .key )
3087+ })
3088+ }
3089+ }
0 commit comments