Disable router when a rule has an error
This commit is contained in:
parent
ac8e47579b
commit
63f65e5b2a
3 changed files with 41 additions and 1 deletions
|
@ -59,7 +59,14 @@ func (r *Router) AddRoute(rule string, priority int, handler http.Handler) error
|
||||||
}
|
}
|
||||||
|
|
||||||
route := r.NewRoute().Handler(handler).Priority(priority)
|
route := r.NewRoute().Handler(handler).Priority(priority)
|
||||||
return addRuleOnRoute(route, buildTree())
|
|
||||||
|
err = addRuleOnRoute(route, buildTree())
|
||||||
|
if err != nil {
|
||||||
|
route.BuildOnly()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type tree struct {
|
type tree struct {
|
||||||
|
|
|
@ -29,6 +29,16 @@ func Test_addRoute(t *testing.T) {
|
||||||
rule: "rulewithnotmatcher",
|
rule: "rulewithnotmatcher",
|
||||||
expectedError: true,
|
expectedError: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Host empty",
|
||||||
|
rule: "Host(``)",
|
||||||
|
expectedError: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "PathPrefix empty",
|
||||||
|
rule: "PathPrefix(``)",
|
||||||
|
expectedError: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "PathPrefix",
|
desc: "PathPrefix",
|
||||||
rule: "PathPrefix(`/foo`)",
|
rule: "PathPrefix(`/foo`)",
|
||||||
|
|
|
@ -62,6 +62,29 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
entryPoints: []string{"web"},
|
entryPoints: []string{"web"},
|
||||||
expected: expectedResult{StatusCode: http.StatusOK},
|
expected: expectedResult{StatusCode: http.StatusOK},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "empty host",
|
||||||
|
routersConfig: map[string]*dynamic.Router{
|
||||||
|
"foo": {
|
||||||
|
EntryPoints: []string{"web"},
|
||||||
|
Service: "foo-service",
|
||||||
|
Rule: "Host(``)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
|
"foo-service": {
|
||||||
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||||
|
Servers: []dynamic.Server{
|
||||||
|
{
|
||||||
|
URL: server.URL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
entryPoints: []string{"web"},
|
||||||
|
expected: expectedResult{StatusCode: http.StatusNotFound},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "no load balancer",
|
desc: "no load balancer",
|
||||||
routersConfig: map[string]*dynamic.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
|
|
Loading…
Reference in a new issue