TestGetOrSetFunc tests the GetOrSetFunc method
(t *testing.T)
| 530 | |
| 531 | // TestGetOrSetFunc tests the GetOrSetFunc method |
| 532 | func TestGetOrSetFunc(t *testing.T) { |
| 533 | slm := NewShardLockMaps() |
| 534 | |
| 535 | // Test setting a new value with function |
| 536 | value, isSet := slm.GetOrSetFunc("key1", func(key string) interface{} { |
| 537 | return "generated_" + key |
| 538 | }) |
| 539 | if !isSet { |
| 540 | t.Error("Expected isSet to be true for new key") |
| 541 | } |
| 542 | if value != "generated_key1" { |
| 543 | t.Error("Expected value to be 'generated_key1'") |
| 544 | } |
| 545 | |
| 546 | // Test getting existing value |
| 547 | value, isSet = slm.GetOrSetFunc("key1", func(key string) interface{} { |
| 548 | return "should_not_be_called" |
| 549 | }) |
| 550 | if isSet { |
| 551 | t.Error("Expected isSet to be false for existing key") |
| 552 | } |
| 553 | if value != "generated_key1" { |
| 554 | t.Error("Expected value to be 'generated_key1'") |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // TestGetOrSetFuncLock tests the GetOrSetFuncLock method |
| 559 | func TestGetOrSetFuncLock(t *testing.T) { |
nothing calls this directly
no test coverage detected