Moar parsers

This commit is contained in:
2025-10-06 23:11:50 +02:00
parent a254b306f2
commit 5f0f4aa96b
14 changed files with 419 additions and 136 deletions

View File

@@ -0,0 +1,51 @@
package parser
import (
"net/netip"
"reflect"
"sort"
"strings"
"testing"
)
func TestMikroTikNetworksParser(t *testing.T) {
test := `
# --------------------------------------------
# IPv4 prefix list of ALIBABA
# --------------------------------------------
# Source: ipapi.is
# --------------------------------------------
# Last Update - Mon Oct 6 06:00:38 +06 2025
# --------------------------------------------
# Total Prefixes: 3764
# --------------------------------------------
# Maintainer: Sakib Mahmud
# --------------------------------------------
/ip firewall address-list
add address=5.181.224.0/23 list=ALIBABA
add address=8.208.0.0/16 list=ALIBABA
add address=8.208.0.0/17 list=ALIBABA
`
want := []netip.Prefix{
netip.MustParsePrefix("5.181.224.0/23"),
netip.MustParsePrefix("8.208.0.0/16"),
netip.MustParsePrefix("8.208.0.0/17"),
}
parsed, ignored, err := ParseNetworks(strings.NewReader(test))
if err != nil {
t.Fatal(err)
return
}
sort.SliceStable(parsed, func(i, j int) bool {
return parsed[i].Addr().Less(parsed[j].Addr())
})
if !reflect.DeepEqual(parsed, want) {
t.Errorf("expected ParseNetworks(mikrotik.rsc) to return %v, got %v", want, parsed)
}
if ignored != 0 {
t.Errorf("expected 0 ignored, got %d", ignored)
}
}