MCPcopy
hub / github.com/pocketbase/pocketbase / TestBaseAppBootstrap

Function TestBaseAppBootstrap

core/base_test.go:60–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func TestBaseAppBootstrap(t *testing.T) {
61 const testDataDir = "./pb_base_app_test_data_dir/"
62 defer os.RemoveAll(testDataDir)
63
64 app := core.NewBaseApp(core.BaseAppConfig{
65 DataDir: testDataDir,
66 })
67 defer app.ResetBootstrapState()
68
69 if app.IsBootstrapped() {
70 t.Fatal("Didn't expect the application to be bootstrapped.")
71 }
72
73 if err := app.Bootstrap(); err != nil {
74 t.Fatal(err)
75 }
76
77 if !app.IsBootstrapped() {
78 t.Fatal("Expected the application to be bootstrapped.")
79 }
80
81 if stat, err := os.Stat(testDataDir); err != nil || !stat.IsDir() {
82 t.Fatal("Expected test data directory to be created.")
83 }
84
85 type nilCheck struct {
86 name string
87 value any
88 expectNil bool
89 }
90
91 runNilChecks := func(checks []nilCheck) {
92 for _, check := range checks {
93 t.Run(check.name, func(t *testing.T) {
94 isNil := check.value == nil
95 if isNil != check.expectNil {
96 t.Fatalf("Expected isNil %v, got %v", check.expectNil, isNil)
97 }
98 })
99 }
100 }
101
102 nilChecksBeforeReset := []nilCheck{
103 {"[before] db", app.DB(), false},
104 {"[before] concurrentDB", app.ConcurrentDB(), false},
105 {"[before] nonconcurrentDB", app.NonconcurrentDB(), false},
106 {"[before] auxDB", app.AuxDB(), false},
107 {"[before] auxConcurrentDB", app.AuxConcurrentDB(), false},
108 {"[before] auxNonconcurrentDB", app.AuxNonconcurrentDB(), false},
109 {"[before] settings", app.Settings(), false},
110 {"[before] logger", app.Logger(), false},
111 {"[before] cached collections", app.Store().Get(core.StoreKeyCachedCollections), false},
112 }
113
114 runNilChecks(nilChecksBeforeReset)
115
116 // reset
117 if err := app.ResetBootstrapState(); err != nil {

Callers

nothing calls this directly

Calls 15

ResetBootstrapStateMethod · 0.95
IsBootstrappedMethod · 0.95
BootstrapMethod · 0.95
DBMethod · 0.95
ConcurrentDBMethod · 0.95
NonconcurrentDBMethod · 0.95
AuxDBMethod · 0.95
AuxConcurrentDBMethod · 0.95
AuxNonconcurrentDBMethod · 0.95
SettingsMethod · 0.95
LoggerMethod · 0.95
StoreMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…