fixed test, deduplicate testdata neighborIDs

This commit is contained in:
Annika Hannig 2022-11-25 12:28:24 +01:00
parent e30d98f0cf
commit 50f155917a
4 changed files with 18 additions and 10 deletions

View File

@ -103,7 +103,7 @@ func (r *RoutesBackend) FindByPrefix(
r.routes.Range(func(k, rs interface{}) bool {
for _, route := range rs.(api.LookupRoutes) {
// Naiive string filtering:
if strings.HasPrefix(strings.ToLower(*route.Network), prefix) {
if strings.HasPrefix(strings.ToLower(route.Network), prefix) {
result = append(result, route)
}
}

View File

@ -7,7 +7,6 @@ import (
"github.com/alice-lg/alice-lg/pkg/api"
"github.com/alice-lg/alice-lg/pkg/config"
"github.com/alice-lg/alice-lg/pkg/pools"
)
func TestRoutesTable(t *testing.T) {
@ -36,7 +35,7 @@ func TestCountRoutesAt(t *testing.T) {
},
Route: &api.Route{
ID: "r1.2.3.4",
Network: pools.Networks4.Acquire("1.2.3.0/24"),
Network: "1.2.3.0/24",
},
}
b.initTable(ctx, tx, "rs1")
@ -88,7 +87,7 @@ func TestFindByNeighbors(t *testing.T) {
},
Route: &api.Route{
ID: "r1.2.3.4",
Network: pools.Networks4.Acquire("1.2.3.0/24"),
Network: "1.2.3.0/24",
},
}
b.initTable(ctx, tx, "rs1")
@ -146,7 +145,7 @@ func TestFindByPrefix(t *testing.T) {
},
Route: &api.Route{
ID: "r1.2.3.4",
Network: pools.Networks4.Acquire("1.2.3.0/24"),
Network: "1.2.3.0/24",
},
}
@ -155,16 +154,16 @@ func TestFindByPrefix(t *testing.T) {
b.persist(ctx, tx, "rs1", r, now)
r.Route.ID = "r4242"
r.Route.Network = pools.Networks4.Acquire("1.2.4.0/24")
r.Route.Network = "1.2.4.0/24"
b.persist(ctx, tx, "rs1", r, now)
r.Route.ID = "r4243"
r.Route.Network = pools.Networks4.Acquire("1.2.5.0/24")
r.Route.Network = "1.2.5.0/24"
r.Neighbor.ID = "n24"
b.persist(ctx, tx, "rs2", r, now)
r.Route.ID = "r4244"
r.Route.Network = pools.Networks4.Acquire("5.5.5.0/24")
r.Route.Network = "5.5.5.0/24"
r.Neighbor.ID = "n25"
b.persist(ctx, tx, "rs1", r, now)

View File

@ -8,6 +8,7 @@ import (
"github.com/alice-lg/alice-lg/pkg/api"
"github.com/alice-lg/alice-lg/pkg/config"
"github.com/alice-lg/alice-lg/pkg/pools"
"github.com/alice-lg/alice-lg/pkg/store/backends/memory"
"github.com/alice-lg/alice-lg/pkg/store/testdata"
)
@ -133,7 +134,7 @@ func TestLookupPrefix(t *testing.T) {
// Check results
for _, prefix := range results {
if strings.HasPrefix(*prefix.Network, query) == false {
if strings.HasPrefix(prefix.Network, query) == false {
t.Error(
"All network addresses should start with the",
"queried prefix",
@ -151,6 +152,7 @@ func TestLookupPrefixForNeighbors(t *testing.T) {
},
},
}
pools.Neighbors.Acquire("ID163_AS31078")
store := makeTestRoutesStore()
@ -171,7 +173,7 @@ func TestLookupPrefixForNeighbors(t *testing.T) {
resultset := []string{}
for _, prefix := range results {
resultset = append(resultset, *prefix.Network)
resultset = append(resultset, prefix.Network)
}
testCheckPrefixesPresence(presence, resultset, t)

View File

@ -6,6 +6,7 @@ import (
"log"
"github.com/alice-lg/alice-lg/pkg/api"
"github.com/alice-lg/alice-lg/pkg/pools"
)
//go:embed routes_response.json
@ -18,6 +19,12 @@ func RoutesResponse() *api.RoutesResponse {
if err != nil {
log.Panic("could not unmarshal response test data:", err)
}
for _, route := range response.Imported {
route.NeighborID = pools.Neighbors.Acquire(*route.NeighborID)
}
for _, route := range response.Filtered {
route.NeighborID = pools.Neighbors.Acquire(*route.NeighborID)
}
return response
}