Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ type RouteLookup struct {
rt *routeTable
}

// Print returns valid routes from the captured routing Table.
func (rl *RouteLookup) Print(pretty eskip.PrettyPrintInfo) string {
return eskip.Print(pretty, rl.rt.validRoutes...)
}

// Do executes the lookup against the captured routing table. Equivalent to
// Routing.Route().
func (rl *RouteLookup) Do(req *http.Request) (*Route, map[string]string) {
Expand Down
59 changes: 59 additions & 0 deletions routing/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"encoding/json"

"github.com/stretchr/testify/assert"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/builtin"
Expand Down Expand Up @@ -1045,3 +1046,61 @@ func TestDuplicateDataClients(t *testing.T) {
}
})
}

func TestRouteLookupPrint(t *testing.T) {
tests := []struct {
name string
routes string
}{
{
name: "empty routing table",
routes: "",
},
{
name: "single route",
routes: `route1: Path("/test") -> "https://example.org";`,
},
{
name: "multiple routes",
routes: `
route1: Path("/test1") -> "https://example1.org";
route2: Path("/test2") -> "https://example2.org";
`,
},
{
name: "multiple routes with invalid",
routes: `
route1: Path("/test1") -> "https://example1.org";
route2: Path("/test2") -> "https://example2.org";
route3: Path("/test3") -> IN() -> "https://example3.org";
`,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualRoutes := eskip.MustParse(tt.routes)
// Create test data client with the routes
dc := testdataclient.New(actualRoutes)
defer dc.Close()

// Create test routing
tr, err := newTestRouting(dc)
if err != nil {
t.Fatalf("failed to create test routing: %v", err)
}
defer tr.close()

// Get RouteLookup and call Print
rl := tr.routing.Get()
prettyInfo := eskip.PrettyPrintInfo{Pretty: false, IndentStr: ""}
result := rl.Print(prettyInfo)
validRoutes := rl.ValidRoutes()
t.Logf("Valid routes %d", len(validRoutes))

expected := eskip.Print(prettyInfo, validRoutes...)

assert.Equal(t, expected, result)
})
}
}