MCPcopy
hub / github.com/pocketbase/pocketbase / TestSettingsValidate

Function TestSettingsValidate

core/settings_model_test.go:190–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestSettingsValidate(t *testing.T) {
191 t.Parallel()
192
193 app, _ := tests.NewTestApp()
194 defer app.Cleanup()
195
196 s := app.Settings()
197
198 // set invalid settings data
199 s.SuperuserIPs = []string{"127.0.0.1", ""}
200 s.Meta.AppName = ""
201 s.Logs.MaxDays = -10
202 s.SMTP.Enabled = true
203 s.SMTP.Host = ""
204 s.S3.Enabled = true
205 s.S3.Endpoint = "invalid"
206 s.Backups.Cron = "invalid"
207 s.Backups.CronMaxKeep = -10
208 s.Batch.Enabled = true
209 s.Batch.MaxRequests = -1
210 s.Batch.Timeout = -1
211 s.RateLimits.Enabled = true
212 s.RateLimits.Rules = nil
213
214 // check if Validate() is triggering the members validate methods.
215 err := app.Validate(s)
216 if err == nil {
217 t.Fatalf("Expected error, got nil")
218 }
219
220 expectations := []string{
221 `"superuserIPs":{`,
222 `"meta":{`,
223 `"logs":{`,
224 `"smtp":{`,
225 `"s3":{`,
226 `"backups":{`,
227 `"batch":{`,
228 `"rateLimits":{`,
229 }
230
231 errBytes, _ := json.Marshal(err)
232 jsonErr := string(errBytes)
233 for _, expected := range expectations {
234 if !strings.Contains(jsonErr, expected) {
235 t.Errorf("Expected error key %s in %v", expected, jsonErr)
236 }
237 }
238}
239
240func TestMetaConfigValidate(t *testing.T) {
241 t.Parallel()

Callers

nothing calls this directly

Calls 4

CleanupMethod · 0.95
NewTestAppFunction · 0.92
SettingsMethod · 0.65
ValidateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…