MCPcopy
hub / github.com/pocketbase/pocketbase / TestNew

Function TestNew

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

Source from the content-addressed store, hash-verified

11)
12
13func TestNew(t *testing.T) {
14 data := map[string]int{"test1": 1, "test2": 2}
15 originalRawData, err := json.Marshal(data)
16 if err != nil {
17 t.Fatal(err)
18 }
19
20 s := store.New(data)
21 s.Set("test3", 3) // add 1 item
22 s.Remove("test1") // remove 1 item
23
24 // check if data was shallow copied
25 rawData, _ := json.Marshal(data)
26 if !bytes.Equal(originalRawData, rawData) {
27 t.Fatalf("Expected data \n%s, \ngot \n%s", originalRawData, rawData)
28 }
29
30 if s.Has("test1") {
31 t.Fatalf("Expected test1 to be deleted, got %v", s.Get("test1"))
32 }
33
34 if v := s.Get("test2"); v != 2 {
35 t.Fatalf("Expected test2 to be %v, got %v", 2, v)
36 }
37
38 if v := s.Get("test3"); v != 3 {
39 t.Fatalf("Expected test3 to be %v, got %v", 3, v)
40 }
41}
42
43func TestReset(t *testing.T) {
44 s := store.New(map[string]int{"test1": 1})

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
SetMethod · 0.65
EqualMethod · 0.65
GetMethod · 0.65
RemoveMethod · 0.45
HasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…