List an AS's prefixes by mask length, shortest first (closes #153)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The AS page sorted its IPv4 and IPv6 prefix lists by network address,
then by mask length. It now sorts them by mask length, shortest first,
and by network address within one mask length, so a /16 comes before a
/24. The sort function is renamed from sortRoutesByNetwork to
sortRoutesByMaskLength to say so.
The handler of /api/v1/as/{asn} does not sort its lists, so it is
unchanged.
Model: opus-5-5
This commit was merged in pull request #181.
This commit is contained in:
@@ -1586,6 +1586,61 @@ func TestASDetailPageShowsBuiltInAS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSortRoutesByMaskLength expects the AS page's prefix lists in mask length
|
||||
// order, shortest first, and in address order within one mask length. Before
|
||||
// the fix they were in address order, so 10.1.0.0/16 came before 11.0.0.0/8
|
||||
// (https://git.eeqj.de/sneak/routewatch/issues/153).
|
||||
func TestSortRoutesByMaskLength(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
prefixes []string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "IPv4",
|
||||
prefixes: []string{
|
||||
"100.64.1.0/24", "11.0.0.0/8", "10.1.0.0/16",
|
||||
"20.0.1.0/24", "172.16.0.0/12", "9.0.0.0/8",
|
||||
},
|
||||
want: []string{
|
||||
"9.0.0.0/8", "11.0.0.0/8", "172.16.0.0/12",
|
||||
"10.1.0.0/16", "20.0.1.0/24", "100.64.1.0/24",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IPv6",
|
||||
prefixes: []string{
|
||||
"2001:db8:1::/48", "2001:db8:8000::/33", "2001:db8:0:1::/64",
|
||||
"2001:db8::/48", "2001:db8::/33",
|
||||
},
|
||||
want: []string{
|
||||
"2001:db8::/33", "2001:db8:8000::/33", "2001:db8::/48",
|
||||
"2001:db8:1::/48", "2001:db8:0:1::/64",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
routes := make([]database.LiveRoute, 0, len(tt.prefixes))
|
||||
for _, prefix := range tt.prefixes {
|
||||
routes = append(routes, database.LiveRoute{Prefix: prefix})
|
||||
}
|
||||
|
||||
sortRoutesByMaskLength(routes)
|
||||
|
||||
got := make([]string, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
got = append(got, route.Prefix)
|
||||
}
|
||||
|
||||
if !slices.Equal(got, tt.want) {
|
||||
t.Errorf("%s: order %v, want %v", tt.name, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestNoOriginHasNoASAnswers stores a route with no known origin, which has
|
||||
// origin AS 0 (https://git.eeqj.de/sneak/routewatch/issues/75). It expects
|
||||
// /as/0 and /api/v1/as/0 to answer 404.
|
||||
|
||||
Reference in New Issue
Block a user