| 380 | } |
| 381 | |
| 382 | func TestLimitsMap_Clone(t *testing.T) { |
| 383 | t.Run("numeric", func(t *testing.T) { |
| 384 | // Create an initial LimitsMap with some data. |
| 385 | original := NewLimitsMap[float64](nil) |
| 386 | original.data["limit1"] = 1.0 |
| 387 | original.data["limit2"] = 2.0 |
| 388 | |
| 389 | // Clone the original LimitsMap. |
| 390 | cloned := original.Clone() |
| 391 | |
| 392 | // Check that the cloned LimitsMap is equal to the original. |
| 393 | require.True(t, original.Equal(cloned), "expected cloned LimitsMap to be different from original") |
| 394 | |
| 395 | // Modify the original LimitsMap and ensure the cloned map is not affected. |
| 396 | original.data["limit1"] = 10.0 |
| 397 | require.False(t, cloned.data["limit1"] == 10.0, "expected cloned LimitsMap to be unaffected by changes to original") |
| 398 | |
| 399 | // Modify the cloned LimitsMap and ensure the original map is not affected. |
| 400 | cloned.data["limit3"] = 3.0 |
| 401 | require.NotContains(t, original.data, "limit3", "expected original LimitsMap to be unaffected by changes to cloned") |
| 402 | }) |
| 403 | |
| 404 | t.Run("string", func(t *testing.T) { |
| 405 | // Create an initial LimitsMap with some data. |
| 406 | original := NewLimitsMap[string](nil) |
| 407 | original.data["limit1"] = "abc" |
| 408 | original.data["limit2"] = "def" |
| 409 | |
| 410 | // Clone the original LimitsMap. |
| 411 | cloned := original.Clone() |
| 412 | |
| 413 | // Check that the cloned LimitsMap is equal to the original. |
| 414 | require.True(t, original.Equal(cloned), "expected cloned LimitsMap to be different from original") |
| 415 | |
| 416 | // Modify the original LimitsMap and ensure the cloned map is not affected. |
| 417 | original.data["limit1"] = "zxcv" |
| 418 | require.False(t, cloned.data["limit1"] == "zxcv", "expected cloned LimitsMap to be unaffected by changes to original") |
| 419 | |
| 420 | // Modify the cloned LimitsMap and ensure the original map is not affected. |
| 421 | cloned.data["limit3"] = "test" |
| 422 | require.NotContains(t, original.data, "limit3", "expected original LimitsMap to be unaffected by changes to cloned") |
| 423 | }) |
| 424 | } |
| 425 | |
| 426 | func TestLimitsMap_updateMap(t *testing.T) { |
| 427 | t.Run("does not apply partial updates", func(t *testing.T) { |