MCPcopy
hub / github.com/pocketbase/pocketbase / TestSuperuserIPsCommand

Function TestSuperuserIPsCommand

cmd/superuser_test.go:406–464  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

404}
405
406func TestSuperuserIPsCommand(t *testing.T) {
407 app, _ := tests.NewTestApp()
408 defer app.Cleanup()
409
410 scenarios := []struct {
411 name string
412 ips []string
413 expectError bool
414 }{
415 {
416 "no ips",
417 nil,
418 false,
419 },
420 {
421 "invalid ips",
422 []string{"127.0.0.1", "invalid"},
423 true,
424 },
425 {
426 "valid ips",
427 []string{"127.0.0.1", "::1", "127.0.0.1/24"},
428 false,
429 },
430 }
431
432 for _, s := range scenarios {
433 t.Run(s.name, func(t *testing.T) {
434 args := []string{"ips"}
435 args = append(args, s.ips...)
436
437 command := cmd.NewSuperuserCommand(app)
438 command.SetArgs(args)
439
440 err := command.Execute()
441
442 hasErr := err != nil
443 if s.expectError != hasErr {
444 t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err)
445 }
446
447 if hasErr {
448 return
449 }
450
451 settingIPs := app.Settings().SuperuserIPs
452
453 if len(settingIPs) != len(s.ips) {
454 t.Fatalf("Expected %d ips, got %d (%v)", len(s.ips), len(settingIPs), settingIPs)
455 }
456
457 for _, ip := range settingIPs {
458 if !slices.Contains(s.ips, ip) {
459 t.Fatalf("Missing expected ip %q (%v)", ip, settingIPs)
460 }
461 }
462 })
463 }

Callers

nothing calls this directly

Calls 6

CleanupMethod · 0.95
NewTestAppFunction · 0.92
NewSuperuserCommandFunction · 0.92
ExecuteMethod · 0.80
SettingsMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…