52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
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)
|
|
}
|
|
|
|
}
|