MCPcopy
hub / github.com/pocketbase/pocketbase / TestGetOrSet

Function TestGetOrSet

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

Source from the content-addressed store, hash-verified

276}
277
278func TestGetOrSet(t *testing.T) {
279 s := store.New(map[string]int{
280 "test1": 0,
281 "test2": 1,
282 "test3": 3,
283 })
284
285 scenarios := []struct {
286 key string
287 value int
288 expected int
289 }{
290 {"test2", 20, 1},
291 {"test3", 2, 3},
292 {"test_new", 20, 20},
293 {"test_new", 50, 20}, // should return the previously inserted value
294 }
295
296 for _, scenario := range scenarios {
297 t.Run(scenario.key, func(t *testing.T) {
298 result := s.GetOrSet(scenario.key, func() int {
299 return scenario.value
300 })
301
302 if result != scenario.expected {
303 t.Fatalf("Expected %v, got %v", scenario.expected, result)
304 }
305 })
306 }
307}
308
309func TestSetIfLessThanLimit(t *testing.T) {
310 s := store.Store[string, int]{}

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
GetOrSetMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…