TestCountApplicableTasks 测试任务计数逻辑
(t *testing.T)
| 252 | |
| 253 | // TestCountApplicableTasks 测试任务计数逻辑 |
| 254 | func TestCountApplicableTasks(t *testing.T) { |
| 255 | tests := []struct { |
| 256 | name string |
| 257 | targets []common.HostInfo |
| 258 | strategy *mockStrategy |
| 259 | setupPlugins func() |
| 260 | expected int |
| 261 | }{ |
| 262 | { |
| 263 | name: "空目标列表", |
| 264 | targets: []common.HostInfo{}, |
| 265 | strategy: &mockStrategy{ |
| 266 | plugins: []string{"ssh", "mysql"}, |
| 267 | isCustomMode: false, |
| 268 | }, |
| 269 | setupPlugins: func() {}, |
| 270 | expected: 0, |
| 271 | }, |
| 272 | { |
| 273 | name: "单目标单插件", |
| 274 | targets: []common.HostInfo{ |
| 275 | {Host: "192.168.1.1", Port: 22}, |
| 276 | }, |
| 277 | strategy: &mockStrategy{ |
| 278 | plugins: []string{"ssh"}, |
| 279 | isCustomMode: false, |
| 280 | }, |
| 281 | setupPlugins: func() {}, |
| 282 | expected: 1, // 取决于插件是否存在 |
| 283 | }, |
| 284 | { |
| 285 | name: "单目标多插件", |
| 286 | targets: []common.HostInfo{ |
| 287 | {Host: "192.168.1.1", Port: 22}, |
| 288 | }, |
| 289 | strategy: &mockStrategy{ |
| 290 | plugins: []string{"ssh", "mysql", "redis"}, |
| 291 | isCustomMode: false, |
| 292 | }, |
| 293 | setupPlugins: func() {}, |
| 294 | expected: 3, // 假设所有插件都存在且适用 |
| 295 | }, |
| 296 | { |
| 297 | name: "多目标单插件", |
| 298 | targets: []common.HostInfo{ |
| 299 | {Host: "192.168.1.1", Port: 22}, |
| 300 | {Host: "192.168.1.2", Port: 22}, |
| 301 | {Host: "192.168.1.3", Port: 22}, |
| 302 | }, |
| 303 | strategy: &mockStrategy{ |
| 304 | plugins: []string{"ssh"}, |
| 305 | isCustomMode: false, |
| 306 | }, |
| 307 | setupPlugins: func() {}, |
| 308 | expected: 3, |
| 309 | }, |
| 310 | { |
| 311 | name: "多目标多插件", |
nothing calls this directly
no test coverage detected