MCPcopy Create free account
hub / github.com/aceld/zinx / TestGetOrSetFunc

Function TestGetOrSetFunc

zutils/shard_lock_map_test.go:532–556  ·  view source on GitHub ↗

TestGetOrSetFunc tests the GetOrSetFunc method

(t *testing.T)

Source from the content-addressed store, hash-verified

530
531// TestGetOrSetFunc tests the GetOrSetFunc method
532func 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
559func TestGetOrSetFuncLock(t *testing.T) {

Callers

nothing calls this directly

Calls 3

GetOrSetFuncMethod · 0.95
NewShardLockMapsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected