(t *testing.T)
| 404 | } |
| 405 | |
| 406 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…