mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fix wildcard alias and some tests
This commit is contained in:
parent
4363ca88aa
commit
c9b5516330
4 changed files with 40 additions and 37 deletions
|
@ -102,8 +102,11 @@ func (p *DockerProvider) routesFromContainerLabels(container *docker.Container)
|
||||||
|
|
||||||
// init entries map for all aliases
|
// init entries map for all aliases
|
||||||
for _, a := range container.Aliases {
|
for _, a := range container.Aliases {
|
||||||
routes[a] = &route.Route{}
|
routes[a] = &route.Route{
|
||||||
routes[a].Metadata.Container = container
|
Metadata: route.Metadata{
|
||||||
|
Container: container,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := E.NewBuilder("label errors")
|
errs := E.NewBuilder("label errors")
|
||||||
|
@ -157,8 +160,11 @@ func (p *DockerProvider) routesFromContainerLabels(container *docker.Container)
|
||||||
// init entry if not exist
|
// init entry if not exist
|
||||||
r, ok := routes[alias]
|
r, ok := routes[alias]
|
||||||
if !ok {
|
if !ok {
|
||||||
r = &route.Route{}
|
r = &route.Route{
|
||||||
r.Metadata.Container = container
|
Metadata: route.Metadata{
|
||||||
|
Container: container,
|
||||||
|
},
|
||||||
|
}
|
||||||
routes[alias] = r
|
routes[alias] = r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ func makeRoutes(cont *types.Container, dockerHostIP ...string) route.Routes {
|
||||||
} else {
|
} else {
|
||||||
host = client.DefaultDockerHost
|
host = client.DefaultDockerHost
|
||||||
}
|
}
|
||||||
|
cont.ID = "test"
|
||||||
p.name = "test"
|
p.name = "test"
|
||||||
routes := Must(p.routesFromContainerLabels(D.FromDocker(cont, host)))
|
routes := Must(p.routesFromContainerLabels(D.FromDocker(cont, host)))
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
|
@ -55,13 +56,13 @@ func TestApplyLabel(t *testing.T) {
|
||||||
"GET /static",
|
"GET /static",
|
||||||
}
|
}
|
||||||
middlewaresExpect := map[string]map[string]any{
|
middlewaresExpect := map[string]map[string]any{
|
||||||
"middleware1": {
|
"request": {
|
||||||
"prop1": "value1",
|
"set_headers": map[string]any{
|
||||||
"prop2": "value2",
|
"X-Header": "value1",
|
||||||
|
},
|
||||||
|
"add_headers": map[string]any{
|
||||||
|
"X-Header2": "value2",
|
||||||
},
|
},
|
||||||
"middleware2": {
|
|
||||||
"prop3": "value3",
|
|
||||||
"prop4": "value4",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
entries := makeRoutes(&types.Container{
|
entries := makeRoutes(&types.Container{
|
||||||
|
@ -78,10 +79,8 @@ func TestApplyLabel(t *testing.T) {
|
||||||
"proxy.*.host": "app",
|
"proxy.*.host": "app",
|
||||||
"proxy.*.port": "4567",
|
"proxy.*.port": "4567",
|
||||||
"proxy.a.path_patterns": pathPatterns,
|
"proxy.a.path_patterns": pathPatterns,
|
||||||
"proxy.a.middlewares.middleware1.prop1": "value1",
|
"proxy.a.middlewares.request.set_headers.X-Header": "value1",
|
||||||
"proxy.a.middlewares.middleware1.prop2": "value2",
|
"proxy.a.middlewares.request.add_headers.X-Header2": "value2",
|
||||||
"proxy.a.middlewares.middleware2.prop3": "value3",
|
|
||||||
"proxy.a.middlewares.middleware2.prop4": "value4",
|
|
||||||
"proxy.a.homepage.show": "true",
|
"proxy.a.homepage.show": "true",
|
||||||
"proxy.a.homepage.icon": "png/adguard-home.png",
|
"proxy.a.homepage.icon": "png/adguard-home.png",
|
||||||
"proxy.a.healthcheck.path": "/ping",
|
"proxy.a.healthcheck.path": "/ping",
|
||||||
|
@ -198,6 +197,7 @@ func TestApplyLabelWithRefIndexError(t *testing.T) {
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
D.LabelAliases: "a,b",
|
D.LabelAliases: "a,b",
|
||||||
"proxy.#1.host": "localhost",
|
"proxy.#1.host": "localhost",
|
||||||
|
"proxy.*.port": "4444",
|
||||||
"proxy.#4.scheme": "https",
|
"proxy.#4.scheme": "https",
|
||||||
},
|
},
|
||||||
}, "")
|
}, "")
|
||||||
|
|
|
@ -89,9 +89,6 @@ func (r *Route) Validate() (err E.Error) {
|
||||||
r.LisURL = E.Collect(errs, net.ParseURL, fmt.Sprintf("%s://%s:%d", r.Scheme, r.Host, r.Port.Listening))
|
r.LisURL = E.Collect(errs, net.ParseURL, fmt.Sprintf("%s://%s:%d", r.Scheme, r.Host, r.Port.Listening))
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
if r.Port.Proxy == 0 && !r.IsDocker() {
|
|
||||||
errs.Adds("missing proxy port")
|
|
||||||
}
|
|
||||||
if r.LoadBalance != nil && r.LoadBalance.Link == "" {
|
if r.LoadBalance != nil && r.LoadBalance.Link == "" {
|
||||||
r.LoadBalance = nil
|
r.LoadBalance = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ var (
|
||||||
ErrInvalidCommandSequence = E.New("invalid command sequence")
|
ErrInvalidCommandSequence = E.New("invalid command sequence")
|
||||||
ErrInvalidSetTarget = E.New("invalid `rule.set` target")
|
ErrInvalidSetTarget = E.New("invalid `rule.set` target")
|
||||||
|
|
||||||
ErrExpectNoArg = E.New("expect no arg")
|
ErrExpectNoArg = E.Wrap(ErrInvalidArguments, "expect no arg")
|
||||||
ErrExpectOneArg = E.New("expect 1 arg")
|
ErrExpectOneArg = E.Wrap(ErrInvalidArguments, "expect 1 arg")
|
||||||
ErrExpectTwoArgs = E.New("expect 2 args")
|
ErrExpectTwoArgs = E.Wrap(ErrInvalidArguments, "expect 2 args")
|
||||||
ErrExpectKVOptionalV = E.New("expect 'key' or 'key value'")
|
ErrExpectKVOptionalV = E.Wrap(ErrInvalidArguments, "expect 'key' or 'key value'")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue