MCPcopy
hub / github.com/shadow1ng/fscan / TestIsContain

Function TestIsContain

core/icmp_test.go:264–317  ·  view source on GitHub ↗

TestIsContain 测试切片查找

(t *testing.T)

Source from the content-addressed store, hash-verified

262
263// TestIsContain 测试切片查找
264func TestIsContain(t *testing.T) {
265 tests := []struct {
266 name string
267 items []string
268 item string
269 expected bool
270 }{
271 {
272 name: "找到元素",
273 items: []string{"192.168.1.1", "192.168.1.2", "192.168.1.3"},
274 item: "192.168.1.2",
275 expected: true,
276 },
277 {
278 name: "未找到元素",
279 items: []string{"192.168.1.1", "192.168.1.2"},
280 item: "192.168.1.3",
281 expected: false,
282 },
283 {
284 name: "空切片",
285 items: []string{},
286 item: "192.168.1.1",
287 expected: false,
288 },
289 {
290 name: "查找空字符串",
291 items: []string{"a", "b", ""},
292 item: "",
293 expected: true,
294 },
295 {
296 name: "单元素切片-匹配",
297 items: []string{"192.168.1.1"},
298 item: "192.168.1.1",
299 expected: true,
300 },
301 {
302 name: "单元素切片-不匹配",
303 items: []string{"192.168.1.1"},
304 item: "192.168.1.2",
305 expected: false,
306 },
307 }
308
309 for _, tt := range tests {
310 t.Run(tt.name, func(t *testing.T) {
311 result := IsContain(tt.items, tt.item)
312 if result != tt.expected {
313 t.Errorf("IsContain() = %v, 期望 %v", result, tt.expected)
314 }
315 })
316 }
317}
318
319// TestExecCommandPing_Blacklist 测试Ping命令注入防护
320func TestExecCommandPing_Blacklist(t *testing.T) {

Callers

nothing calls this directly

Calls 2

IsContainFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected