TestPool_Create 测试创建 Agent
(t *testing.T)
| 61 | |
| 62 | // TestPool_Create 测试创建 Agent |
| 63 | func TestPool_Create(t *testing.T) { |
| 64 | deps := createTestDeps(t) |
| 65 | pool := NewPool(&PoolOptions{ |
| 66 | Dependencies: deps, |
| 67 | MaxAgents: 5, |
| 68 | }) |
| 69 | defer func() { |
| 70 | if err := pool.Shutdown(); err != nil { |
| 71 | t.Errorf("Shutdown failed: %v", err) |
| 72 | } |
| 73 | }() |
| 74 | |
| 75 | ctx := context.Background() |
| 76 | |
| 77 | // 创建 Agent |
| 78 | config := createTestConfig("test-agent-1") |
| 79 | |
| 80 | ag, err := pool.Create(ctx, config) |
| 81 | if err != nil { |
| 82 | t.Fatalf("Failed to create agent: %v", err) |
| 83 | } |
| 84 | |
| 85 | if ag == nil { |
| 86 | t.Fatal("Agent is nil") |
| 87 | } |
| 88 | |
| 89 | // 验证 Agent 在池中 |
| 90 | retrievedAg, exists := pool.Get("test-agent-1") |
| 91 | if !exists { |
| 92 | t.Fatal("Agent not found in pool") |
| 93 | } |
| 94 | |
| 95 | if retrievedAg != ag { |
| 96 | t.Error("Retrieved agent is different from created agent") |
| 97 | } |
| 98 | |
| 99 | // 验证池大小 |
| 100 | if pool.Size() != 1 { |
| 101 | t.Errorf("Expected pool size 1, got %d", pool.Size()) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // TestPool_CreateDuplicate 测试重复创建相同 ID 的 Agent |
| 106 | func TestPool_CreateDuplicate(t *testing.T) { |
nothing calls this directly
no test coverage detected