fix: harden scan edge cases

This commit is contained in:
ZacharyZcR
2026-06-01 03:32:13 +08:00
parent 8b558b4f12
commit 8ec96bfe6d
21 changed files with 534 additions and 67 deletions
+29
View File
@@ -0,0 +1,29 @@
package core
import (
"os"
"reflect"
"testing"
"github.com/shadow1ng/fscan/common"
)
func TestLoadHostExcludesIncludesExcludeFile(t *testing.T) {
path := t.TempDir() + "/exclude.txt"
if err := os.WriteFile(path, []byte("192.168.1.2\n# comment\n192.168.1.3\n"), 0o600); err != nil {
t.Fatalf("WriteFile error = %v", err)
}
got, err := loadHostExcludes(&common.FlagVars{
ExcludeHosts: "192.168.1.1",
ExcludeHostsFile: path,
})
if err != nil {
t.Fatalf("loadHostExcludes error = %v", err)
}
want := []string{"192.168.1.1", "192.168.1.2", "192.168.1.3"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("loadHostExcludes = %#v, want %#v", got, want)
}
}