diff --git a/registry/consul/routecmd.go b/registry/consul/routecmd.go index 7a17ef0be..6eae8ad3b 100644 --- a/registry/consul/routecmd.go +++ b/registry/consul/routecmd.go @@ -26,6 +26,9 @@ type routecmd struct { func (r routecmd) build() []string { var svctags, routetags []string for _, t := range r.svc.ServiceTags { + + t = strings.TrimSpace(t) + if strings.HasPrefix(t, r.prefix) { routetags = append(routetags, t) } else { diff --git a/registry/consul/routecmd_test.go b/registry/consul/routecmd_test.go index d6b19b031..46f3e2e9f 100644 --- a/registry/consul/routecmd_test.go +++ b/registry/consul/routecmd_test.go @@ -28,6 +28,53 @@ func TestRouteCmd(t *testing.T) { `route add svc-1 foo/bar http://1.1.1.1:2222/`, }, }, + { + name: "http single tag with a space", + r: routecmd{ + prefix: "p-", + svc: &api.CatalogService{ + ServiceName: "svc-1", + ServiceAddress: "1.1.1.1", + ServicePort: 2222, + ServiceTags: []string{` p-foo/bar`}, + }, + }, + cfg: []string{ + `route add svc-1 foo/bar http://1.1.1.1:2222/`, + }, + }, + { + name: "http multiple tags", + r: routecmd{ + prefix: "p-", + svc: &api.CatalogService{ + ServiceName: "svc-1", + ServiceAddress: "1.1.1.1", + ServicePort: 2222, + ServiceTags: []string{`p-foo/bar`, `p-test/foo`}, + }, + }, + cfg: []string{ + `route add svc-1 foo/bar http://1.1.1.1:2222/`, + `route add svc-1 test/foo http://1.1.1.1:2222/`, + }, + }, + { + name: "http multiple routes with space prefix route", + r: routecmd{ + prefix: "p-", + svc: &api.CatalogService{ + ServiceName: "svc-1", + ServiceAddress: "1.1.1.1", + ServicePort: 2222, + ServiceTags: []string{`p-foo/bar`, ` p-test/foo`}, + }, + }, + cfg: []string{ + `route add svc-1 foo/bar http://1.1.1.1:2222/`, + `route add svc-1 test/foo http://1.1.1.1:2222/`, + }, + }, { name: "tcp", r: routecmd{