TestLockFunc tests the LockFunc method
(t *testing.T)
| 663 | |
| 664 | // TestLockFunc tests the LockFunc method |
| 665 | func TestLockFunc(t *testing.T) { |
| 666 | slm := NewShardLockMaps() |
| 667 | slm.Set("key1", "value1") |
| 668 | slm.Set("key2", "value2") |
| 669 | |
| 670 | // Test modifying all shards |
| 671 | slm.LockFunc(func(data map[string]interface{}) { |
| 672 | for key, val := range data { |
| 673 | if str, ok := val.(string); ok { |
| 674 | data[key] = str + "_modified" |
| 675 | } |
| 676 | } |
| 677 | }) |
| 678 | |
| 679 | value1, _ := slm.Get("key1") |
| 680 | value2, _ := slm.Get("key2") |
| 681 | if value1 != "value1_modified" || value2 != "value2_modified" { |
| 682 | t.Error("Expected all values to be modified") |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | // TestRLockFunc tests the RLockFunc method |
| 687 | func TestRLockFunc(t *testing.T) { |
nothing calls this directly
no test coverage detected