TestOptionsValidation 测试配置验证
(t *testing.T)
| 442 | |
| 443 | // TestOptionsValidation 测试配置验证 |
| 444 | func TestOptionsValidation(t *testing.T) { |
| 445 | // 测试 nil Pool |
| 446 | opts := &Options{} |
| 447 | err := opts.Validate() |
| 448 | if err == nil { |
| 449 | t.Error("Expected error for nil pool") |
| 450 | } |
| 451 | |
| 452 | // 测试无效端口 |
| 453 | deps := createTestDependencies(t) |
| 454 | pool := core.NewPool(&core.PoolOptions{ |
| 455 | Dependencies: deps, |
| 456 | MaxAgents: 5, |
| 457 | }) |
| 458 | |
| 459 | opts = &Options{ |
| 460 | Name: "TestOS", |
| 461 | Port: 70000, // 无效端口 |
| 462 | Pool: pool, |
| 463 | } |
| 464 | err = opts.Validate() |
| 465 | if err == nil { |
| 466 | t.Error("Expected error for invalid port") |
| 467 | } |
| 468 | |
| 469 | // 测试有效配置 |
| 470 | opts = &Options{ |
| 471 | Name: "TestOS", |
| 472 | Port: 8080, |
| 473 | Pool: pool, |
| 474 | } |
| 475 | err = opts.Validate() |
| 476 | if err != nil { |
| 477 | t.Errorf("Valid options should not return error: %v", err) |
| 478 | } |
| 479 | } |
nothing calls this directly
no test coverage detected