package capture import ( "testing" ) // TestValidateBPFFilter verifies that a valid BPF expression returns nil error. func TestValidateBPFFilter(t *testing.T) { if err := ValidateBPFFilter("port 53"); err != nil { t.Errorf("ValidateBPFFilter(\"port 53\") = %v; want nil", err) } } // TestValidateBPFFilterEmpty verifies that empty string returns nil (no filter). func TestValidateBPFFilterEmpty(t *testing.T) { if err := ValidateBPFFilter(""); err != nil { t.Errorf("ValidateBPFFilter(\"\") = %v; want nil", err) } } // TestValidateBPFFilterWhitespace verifies that whitespace-only string returns nil. func TestValidateBPFFilterWhitespace(t *testing.T) { if err := ValidateBPFFilter(" "); err != nil { t.Errorf("ValidateBPFFilter(\" \") = %v; want nil", err) } } // TestValidateBPFFilterInvalid verifies that invalid BPF expression returns error. func TestValidateBPFFilterInvalid(t *testing.T) { err := ValidateBPFFilter("invalid garbage xyz") if err == nil { t.Error("ValidateBPFFilter(\"invalid garbage xyz\") = nil; want non-nil error") } } // TestCompileSoftwareBPF verifies that a valid expression compiles to a non-nil VM. func TestCompileSoftwareBPF(t *testing.T) { vm, err := CompileSoftwareBPF("tcp") if err != nil { t.Errorf("CompileSoftwareBPF(\"tcp\") error: %v", err) } if vm == nil { t.Error("CompileSoftwareBPF(\"tcp\") returned nil VM; want non-nil") } } // TestCompileSoftwareBPFInvalid verifies that invalid expression returns nil VM and non-nil error. func TestCompileSoftwareBPFInvalid(t *testing.T) { vm, err := CompileSoftwareBPF("invalid garbage") if err == nil { t.Error("CompileSoftwareBPF(\"invalid garbage\") error = nil; want non-nil") } if vm != nil { t.Error("CompileSoftwareBPF(\"invalid garbage\") VM non-nil; want nil") } }