MCPcopy
hub / github.com/pocketbase/pocketbase / TestReloadSettings

Function TestReloadSettings

core/settings_query_test.go:13–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestReloadSettings(t *testing.T) {
14 app, _ := tests.NewTestApp()
15 defer app.Cleanup()
16
17 // cleanup all stored settings
18 // ---
19 if _, err := app.DB().NewQuery("DELETE from _params;").Execute(); err != nil {
20 t.Fatalf("Failed to delete all test settings: %v", err)
21 }
22
23 // check if the new settings are saved in the db
24 // ---
25 app.Settings().Meta.AppName = "test_name_after_delete"
26
27 app.ResetEventCalls()
28 if err := app.ReloadSettings(); err != nil {
29 t.Fatalf("Failed to reload the settings after delete: %v", err)
30 }
31 testEventCalls(t, app, map[string]int{
32 "OnModelCreate": 1,
33 "OnModelCreateExecute": 1,
34 "OnModelAfterCreateSuccess": 1,
35 "OnModelValidate": 1,
36 "OnSettingsReload": 1,
37 })
38
39 param := &core.Param{}
40 err := app.ModelQuery(param).Model("settings", param)
41 if err != nil {
42 t.Fatalf("Expected new settings to be persisted, got %v", err)
43 }
44
45 if !strings.Contains(param.Value.String(), "test_name_after_delete") {
46 t.Fatalf("Expected to find AppName test_name_after_delete in\n%s", param.Value.String())
47 }
48
49 // change the db entry and reload the app settings (ensure that there was no db update)
50 // ---
51 param.Value = types.JSONRaw([]byte(`{"meta": {"appName":"test_name_after_update"}}`))
52 if err := app.Save(param); err != nil {
53 t.Fatalf("Failed to update the test settings: %v", err)
54 }
55
56 app.ResetEventCalls()
57 if err := app.ReloadSettings(); err != nil {
58 t.Fatalf("Failed to reload app settings: %v", err)
59 }
60 testEventCalls(t, app, map[string]int{
61 "OnSettingsReload": 1,
62 })
63
64 // try to reload again without doing any changes
65 // ---
66 app.ResetEventCalls()
67 if err := app.ReloadSettings(); err != nil {
68 t.Fatalf("Failed to reload app settings without change: %v", err)
69 }
70 testEventCalls(t, app, map[string]int{

Callers

nothing calls this directly

Calls 14

CleanupMethod · 0.95
ResetEventCallsMethod · 0.95
NewTestAppFunction · 0.92
JSONRawTypeAlias · 0.92
testEventCallsFunction · 0.85
ExecuteMethod · 0.80
NewQueryMethod · 0.80
ModelMethod · 0.80
DBMethod · 0.65
SettingsMethod · 0.65
ReloadSettingsMethod · 0.65
ModelQueryMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…