MCPcopy
hub / github.com/pocketbase/pocketbase / TestSetFunc

Function TestSetFunc

tools/store/store_test.go:252–276  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

250}
251
252func TestSetFunc(t *testing.T) {
253 s := store.Store[string, int]{}
254
255 // non existing value
256 s.SetFunc("test", func(old int) int {
257 if old != 0 {
258 t.Fatalf("Expected old value %d, got %d", 0, old)
259 }
260 return old + 2
261 })
262 if v := s.Get("test"); v != 2 {
263 t.Fatalf("Expected the stored value to be %d, got %d", 2, v)
264 }
265
266 // increment existing value
267 s.SetFunc("test", func(old int) int {
268 if old != 2 {
269 t.Fatalf("Expected old value %d, got %d", 2, old)
270 }
271 return old + 1
272 })
273 if v := s.Get("test"); v != 3 {
274 t.Fatalf("Expected the stored value to be %d, got %d", 3, v)
275 }
276}
277
278func TestGetOrSet(t *testing.T) {
279 s := store.New(map[string]int{

Callers

nothing calls this directly

Calls 2

SetFuncMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…