MCPcopy Index your code
hub / github.com/aceld/zinx / TestRemoveCb

Function TestRemoveCb

zutils/shard_lock_map_test.go:134–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestRemoveCb(t *testing.T) {
135 slm := NewShardLockMaps()
136
137 tony := TestUser{"tony"}
138 slm.Set("tony", tony)
139 david := TestUser{"david"}
140 slm.Set("david", david)
141
142 var (
143 mapKey string
144 mapVal interface{}
145 wasFound bool
146 )
147 cb := func(key string, val interface{}, exists bool) bool {
148 mapKey = key
149 mapVal = val
150 wasFound = exists
151
152 if user, ok := val.(TestUser); ok {
153 return user.name == "tony"
154 }
155 return false
156 }
157
158 result := slm.RemoveCb("tony", cb)
159 if !result {
160 t.Errorf("Result was not true")
161 }
162
163 if mapKey != "tony" {
164 t.Error("Wrong key was provided to the callback")
165 }
166
167 if mapVal != tony {
168 t.Errorf("Wrong value was provided to the value")
169 }
170
171 if !wasFound {
172 t.Errorf("Key was not found")
173 }
174
175 if slm.Has("tony") {
176 t.Errorf("Key was not removed")
177 }
178
179 result = slm.RemoveCb("david", cb)
180 if result {
181 t.Errorf("Result was true")
182 }
183
184 if mapKey != "david" {
185 t.Error("Wrong key was provided to the callback")
186 }
187
188 if mapVal != david {
189 t.Errorf("Wrong value was provided to the value")
190 }
191

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
RemoveCbMethod · 0.95
HasMethod · 0.95
NewShardLockMapsFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected