(t *testing.T)
| 183 | } |
| 184 | |
| 185 | func TestGenerateDropScriptWithCIDRFilter(t *testing.T) { |
| 186 | _, cidr, err := net.ParseCIDR("10.0.0.0/24") |
| 187 | if err != nil { |
| 188 | t.Fatalf("failed to parse CIDR: %v", err) |
| 189 | } |
| 190 | |
| 191 | config := TraceConfig{ |
| 192 | FilterCIDRs: []*net.IPNet{cidr}, |
| 193 | OutputJSON: false, |
| 194 | } |
| 195 | |
| 196 | gen := NewScriptGenerator(config) |
| 197 | filter := gen.buildSkbIPFilterCondition() |
| 198 | |
| 199 | // Should contain hex network |
| 200 | if !strings.Contains(filter, "0x0a000000") { |
| 201 | t.Errorf("expected filter to contain hex network 0x0a000000, got: %s", filter) |
| 202 | } |
| 203 | |
| 204 | // Should contain hex mask for /24 |
| 205 | if !strings.Contains(filter, "0xffffff00") { |
| 206 | t.Errorf("expected filter to contain hex mask 0xffffff00, got: %s", filter) |
| 207 | } |
| 208 | |
| 209 | // Should use bswap() for endianness |
| 210 | if !strings.Contains(filter, "bswap($saddr_raw)") { |
| 211 | t.Errorf("expected filter to use bswap() for endianness conversion, got: %s", filter) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | func TestGenerateDropScriptJSONOutput(t *testing.T) { |
| 216 | config := TraceConfig{ |
nothing calls this directly
no test coverage detected