@@ -198,7 +198,7 @@ func TestParseCacheConfigMap(t *testing.T) {
198198}
199199
200200func TestOnCacheConfigChanged (t * testing.T ) {
201- // Test that onCacheConfigChanged updates the shared cache
201+ // Test that onCacheConfigChanged updates the shared cache with new config values
202202 config := & cacheConfig {
203203 maxSize : 500 ,
204204 ttl : 10 * time .Minute ,
@@ -207,25 +207,56 @@ func TestOnCacheConfigChanged(t *testing.T) {
207207 // Call onCacheConfigChanged to update the shared cache
208208 onCacheConfigChanged ("test-config" , config )
209209
210- // Verify the shared cache was updated by checking we can still get it
211- // We can't directly verify the size/ttl without accessing the internal cache,
212- // but we can verify it doesn't panic and returns a valid cache
210+ // Verify the shared cache was updated with the correct config values
213211 ctx := logtesting .TestContextWithLogger (t )
214212 cache := Get (ctx )
215213 if cache == nil {
216- t .Error ("Expected cache after config change but got nil" )
214+ t .Fatal ("Expected cache after config change but got nil" )
215+ }
216+
217+ // Verify TTL was applied
218+ if cache .TTL () != config .ttl {
219+ t .Errorf ("Expected TTL to be %v, got %v" , config .ttl , cache .TTL ())
220+ }
221+
222+ // Verify MaxSize was applied
223+ if cache .MaxSize () != config .maxSize {
224+ t .Errorf ("Expected MaxSize to be %d, got %d" , config .maxSize , cache .MaxSize ())
217225 }
218226}
219227
220228func TestOnCacheConfigChangedWithInvalidType (t * testing.T ) {
229+ // First, set up a known good config
230+ goodConfig := & cacheConfig {
231+ maxSize : defaultCacheSize ,
232+ ttl : defaultExpiration ,
233+ }
234+ onCacheConfigChanged ("test-config" , goodConfig )
235+
236+ ctx := logtesting .TestContextWithLogger (t )
237+ cacheBefore := Get (ctx )
238+ if cacheBefore == nil {
239+ t .Fatal ("Expected cache before invalid config change" )
240+ }
241+ ttlBefore := cacheBefore .TTL ()
242+ maxSizeBefore := cacheBefore .MaxSize ()
243+
221244 // Test that onCacheConfigChanged handles invalid types gracefully
222- // This should not panic
245+ // This should not panic and should preserve the existing cache
223246 onCacheConfigChanged ("test-config" , "invalid-type" )
224247
225- // Verify we can still get the cache
226- ctx := logtesting .TestContextWithLogger (t )
227- cache := Get (ctx )
228- if cache == nil {
229- t .Error ("Expected cache after invalid config change but got nil" )
248+ // Verify we can still get the cache and it wasn't modified
249+ cacheAfter := Get (ctx )
250+ if cacheAfter == nil {
251+ t .Fatal ("Expected cache after invalid config change but got nil" )
252+ }
253+
254+ // Verify cache config wasn't changed by invalid input
255+ if cacheAfter .TTL () != ttlBefore {
256+ t .Errorf ("Expected TTL to remain %v after invalid config, got %v" , ttlBefore , cacheAfter .TTL ())
257+ }
258+
259+ if cacheAfter .MaxSize () != maxSizeBefore {
260+ t .Errorf ("Expected MaxSize to remain %d after invalid config, got %d" , maxSizeBefore , cacheAfter .MaxSize ())
230261 }
231262}
0 commit comments