func (appRunner *appRunner) buildRoutes(noRoutes bool, routeOverrides RouteOverrides, tcpRoutes TcpRoutes) route_helpers.Routes { var routes route_helpers.Routes var appRoutes route_helpers.AppRoutes if noRoutes { appRoutes = route_helpers.AppRoutes{} } else if len(routeOverrides) > 0 { routeMap := make(map[uint16][]string) for _, override := range routeOverrides { routeMap[override.Port] = append(routeMap[override.Port], appRunner.appendDomain(override.HostnamePrefix)) } for port, hostnames := range routeMap { appRoutes = append(appRoutes, route_helpers.AppRoute{ Hostnames: hostnames, Port: port, }) } } var appTcpRoutes route_helpers.TcpRoutes if !noRoutes && len(tcpRoutes) > 0 { for _, tcpRoute := range tcpRoutes { appTcpRoutes = append(appTcpRoutes, route_helpers.TcpRoute{ ExternalPort: tcpRoute.ExternalPort, Port: tcpRoute.Port, }) } routes.TcpRoutes = appTcpRoutes } routes.AppRoutes = appRoutes return routes }
It("returns map of ports to slice of hostnames", func() { expectedHostnamesByPort := map[uint16][]string{ 11111: []string{"foo1.example.com", "bar1.examaple.com"}, 22222: []string{"foo2.example.com", "bar2.examaple.com"}, 33333: []string{"foo3.example.com", "bar3.examaple.com"}, } Expect(appRoutes.HostnamesByPort()).To(Equal(expectedHostnamesByPort)) }) }) Describe("Routes", func() { var ( routes route_helpers.Routes tcpRoute1, tcpRoute2 route_helpers.TcpRoute diegoSSHRoute *route_helpers.DiegoSSHRoute ) BeforeEach(func() { tcpRoute1 = route_helpers.TcpRoute{ RouterGroupGuid: route_helpers.DefaultRouterGroupGuid, ExternalPort: 50000, Port: 5222, } tcpRoute2 = route_helpers.TcpRoute{ RouterGroupGuid: route_helpers.DefaultRouterGroupGuid, ExternalPort: 51000, Port: 5223, } diegoSSHRoute = &route_helpers.DiegoSSHRoute{