MCPcopy
hub / github.com/pocketbase/pocketbase / TestSkipBootstrap

Function TestSkipBootstrap

pocketbase_test.go:133–210  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func TestSkipBootstrap(t *testing.T) {
134 // copy os.Args
135 originalArgs := make([]string, len(os.Args))
136 copy(originalArgs, os.Args)
137 defer func() {
138 // restore os.Args
139 os.Args = originalArgs
140 }()
141
142 tempDir := filepath.Join(os.TempDir(), "temp_pb_data")
143 defer os.RemoveAll(tempDir)
144
145 // already bootstrapped
146 app0 := NewWithConfig(Config{DefaultDataDir: tempDir})
147 app0.Bootstrap()
148 if v := app0.skipBootstrap(); !v {
149 t.Fatal("[bootstrapped] Expected true, got false")
150 }
151
152 // unknown command
153 os.Args = os.Args[:1]
154 os.Args = append(os.Args, "demo")
155 app1 := NewWithConfig(Config{DefaultDataDir: tempDir})
156 app1.RootCmd.AddCommand(&cobra.Command{Use: "test"})
157 if v := app1.skipBootstrap(); !v {
158 t.Fatal("[unknown] Expected true, got false")
159 }
160
161 // default flags
162 flagScenarios := []struct {
163 name string
164 short string
165 }{
166 {"help", "h"},
167 {"version", "v"},
168 }
169
170 for _, s := range flagScenarios {
171 // base flag
172 os.Args = os.Args[:1]
173 os.Args = append(os.Args, "--"+s.name)
174 app1 := NewWithConfig(Config{DefaultDataDir: tempDir})
175 if v := app1.skipBootstrap(); !v {
176 t.Fatalf("[--%s] Expected true, got false", s.name)
177 }
178
179 // short flag
180 os.Args = os.Args[:1]
181 os.Args = append(os.Args, "-"+s.short)
182 app2 := NewWithConfig(Config{DefaultDataDir: tempDir})
183 if v := app2.skipBootstrap(); !v {
184 t.Fatalf("[-%s] Expected true, got false", s.short)
185 }
186
187 customCmd := &cobra.Command{Use: "custom"}
188 customCmd.PersistentFlags().BoolP(s.name, s.short, false, "")
189
190 // base flag in custom command

Callers

nothing calls this directly

Calls 5

copyFunction · 0.85
NewWithConfigFunction · 0.85
skipBootstrapMethod · 0.80
BootstrapMethod · 0.65
RemoveAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…