func (appRunner *appRunner) updateLrpRoutes(name string, routes RouteOverrides) error { appRoutes := route_helpers.AppRoutes{} routeMap := make(map[uint16][]string) for _, override := range routes { 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, }) } err := appRunner.receptorClient.UpdateDesiredLRP( name, receptor.DesiredLRPUpdateRequest{ Routes: appRoutes.RoutingInfo(), }, ) return err }
Port: 22222, } appRoute3 = route_helpers.AppRoute{ Hostnames: []string{"foo3.example.com", "bar3.examaple.com"}, Port: 33333, } appRoutes = route_helpers.AppRoutes{appRoute1, appRoute2, appRoute3} }) Describe("AppRoutes", func() { Describe("RoutingInfo", func() { var routingInfo receptor.RoutingInfo JustBeforeEach(func() { routingInfo = appRoutes.RoutingInfo() }) It("maps the serialized routes to the correct key", func() { expectedBytes := []byte(`[{"hostnames":["foo1.example.com","bar1.examaple.com"],"port":11111},{"hostnames":["foo2.example.com","bar2.examaple.com"],"port":22222},{"hostnames":["foo3.example.com","bar3.examaple.com"],"port":33333}]`) Expect(appRoutes.RoutingInfo()["cf-router"].MarshalJSON()).To(MatchJSON(expectedBytes)) }) Context("when AppRoutes is empty", func() { BeforeEach(func() { appRoutes = route_helpers.AppRoutes{} }) It("marshals an empty list", func() { payload, err := routingInfo["cf-router"].MarshalJSON() Expect(err).NotTo(HaveOccurred())