TestAddInterface 测试添加 Interface
(t *testing.T)
| 232 | |
| 233 | // TestAddInterface 测试添加 Interface |
| 234 | func TestAddInterface(t *testing.T) { |
| 235 | deps := createTestDependencies(t) |
| 236 | pool := core.NewPool(&core.PoolOptions{ |
| 237 | Dependencies: deps, |
| 238 | MaxAgents: 5, |
| 239 | }) |
| 240 | |
| 241 | os, err := New(&Options{ |
| 242 | Name: "TestOS", |
| 243 | Port: 8080, |
| 244 | Pool: pool, |
| 245 | }) |
| 246 | if err != nil { |
| 247 | t.Fatalf("Failed to create AsterOS: %v", err) |
| 248 | } |
| 249 | |
| 250 | // 创建测试 Interface |
| 251 | testInterface := &TestInterface{ |
| 252 | name: "test-interface", |
| 253 | typ: "test", |
| 254 | } |
| 255 | |
| 256 | // 添加 Interface |
| 257 | err = os.AddInterface(testInterface) |
| 258 | if err != nil { |
| 259 | t.Fatalf("Failed to add interface: %v", err) |
| 260 | } |
| 261 | |
| 262 | // 重复添加应该失败 |
| 263 | err = os.AddInterface(testInterface) |
| 264 | if err == nil { |
| 265 | t.Error("Expected error for duplicate interface") |
| 266 | } |
| 267 | |
| 268 | // 移除 Interface |
| 269 | err = os.RemoveInterface("test-interface") |
| 270 | if err != nil { |
| 271 | t.Fatalf("Failed to remove interface: %v", err) |
| 272 | } |
| 273 | |
| 274 | // 移除不存在的 Interface 应该失败 |
| 275 | err = os.RemoveInterface("non-existent") |
| 276 | if err == nil { |
| 277 | t.Error("Expected error for non-existent interface") |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | // TestLifecycle 测试生命周期 |
| 282 | func TestLifecycle(t *testing.T) { |
nothing calls this directly
no test coverage detected