func CCRouteInfoToRoutes(ccRoutes cc_messages.CCRouteInfo, ports []uint32) (models.Routes, error) { var defaultPort uint32 if len(ports) > 0 { defaultPort = ports[0] } else { defaultPort = 8080 } routes := models.Routes{} if ccRoutes[cc_messages.CC_HTTP_ROUTES] != nil { httpRoutingInfo, err := constructHttpRoutes(ccRoutes, defaultPort) if err != nil { return nil, err } routes[cfroutes.CF_ROUTER] = httpRoutingInfo[cfroutes.CF_ROUTER] } else { cfRoutes := cfroutes.CFRoutes{} httpRoutingInfo := cfRoutes.RoutingInfo() routes[cfroutes.CF_ROUTER] = httpRoutingInfo[cfroutes.CF_ROUTER] } if ccRoutes[cc_messages.CC_TCP_ROUTES] != nil { tcpRoutingInfo, err := constructTcpRoutes(ccRoutes) if err != nil { return nil, err } routes[tcp_routes.TCP_ROUTER] = tcpRoutingInfo[tcp_routes.TCP_ROUTER] } else { tcpRoutes := tcp_routes.TCPRoutes{} tcpRoutingInfo := tcpRoutes.RoutingInfo() routes[tcp_routes.TCP_ROUTER] = (*tcpRoutingInfo)[tcp_routes.TCP_ROUTER] } return routes, nil }
import ( "encoding/json" "github.com/cloudfoundry-incubator/bbs/models" "github.com/cloudfoundry-incubator/routing-info/cfroutes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("RoutingInfoHelpers", func() { var ( route1 cfroutes.CFRoute route2 cfroutes.CFRoute route3 cfroutes.CFRoute routes cfroutes.CFRoutes ) BeforeEach(func() { route1 = cfroutes.CFRoute{ Hostnames: []string{"foo1.example.com", "bar1.examaple.com"}, Port: 11111, } route2 = cfroutes.CFRoute{ Hostnames: []string{"foo2.example.com", "bar2.examaple.com"}, Port: 22222, } route3 = cfroutes.CFRoute{ Hostnames: []string{"foo3.example.com", "bar3.examaple.com"},
package routing_table_test import ( "github.com/cloudfoundry-incubator/bbs/models" "github.com/cloudfoundry-incubator/route-emitter/routing_table" "github.com/cloudfoundry-incubator/routing-info/cfroutes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("ByRoutingKey", func() { Describe("RoutesByRoutingKeyFromDesireds", func() { It("should build a map of routes", func() { abcRoutes := cfroutes.CFRoutes{ {Hostnames: []string{"foo.com", "bar.com"}, Port: 8080, RouteServiceUrl: "https://something.creative"}, {Hostnames: []string{"foo.example.com"}, Port: 9090}, } defRoutes := cfroutes.CFRoutes{ {Hostnames: []string{"baz.com"}, Port: 8080}, } routes := routing_table.RoutesByRoutingKeyFromSchedulingInfos([]*models.DesiredLRPSchedulingInfo{ {DesiredLRPKey: models.NewDesiredLRPKey("abc", "tests", "abc-guid"), Routes: abcRoutes.RoutingInfo()}, {DesiredLRPKey: models.NewDesiredLRPKey("def", "tests", "def-guid"), Routes: defRoutes.RoutingInfo()}, }) Expect(routes).To(HaveLen(3)) Expect(routes[routing_table.RoutingKey{ProcessGuid: "abc", ContainerPort: 8080}].Hostnames).To(Equal([]string{"foo.com", "bar.com"})) Expect(routes[routing_table.RoutingKey{ProcessGuid: "abc", ContainerPort: 8080}].LogGuid).To(Equal("abc-guid")) Expect(routes[routing_table.RoutingKey{ProcessGuid: "abc", ContainerPort: 8080}].RouteServiceUrl).To(Equal("https://something.creative"))