TestGetOrSetFuncLock tests the GetOrSetFuncLock method
(t *testing.T)
| 557 | |
| 558 | // TestGetOrSetFuncLock tests the GetOrSetFuncLock method |
| 559 | func TestGetOrSetFuncLock(t *testing.T) { |
| 560 | slm := NewShardLockMaps() |
| 561 | |
| 562 | // Test setting a new value with function in lock |
| 563 | value, isSet := slm.GetOrSetFuncLock("key1", func(key string) interface{} { |
| 564 | return "locked_" + key |
| 565 | }) |
| 566 | if !isSet { |
| 567 | t.Error("Expected isSet to be true for new key") |
| 568 | } |
| 569 | if value != "locked_key1" { |
| 570 | t.Error("Expected value to be 'locked_key1'") |
| 571 | } |
| 572 | |
| 573 | // Test getting existing value |
| 574 | value, isSet = slm.GetOrSetFuncLock("key1", func(key string) interface{} { |
| 575 | return "should_not_be_called" |
| 576 | }) |
| 577 | if isSet { |
| 578 | t.Error("Expected isSet to be false for existing key") |
| 579 | } |
| 580 | if value != "locked_key1" { |
| 581 | t.Error("Expected value to be 'locked_key1'") |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | // TestMGet tests the MGet method |
| 586 | func TestMGet(t *testing.T) { |
nothing calls this directly
no test coverage detected