Expect(log).To(ContainSubstring("RESPONSE: ")) Expect(log).To(ContainSubstring("HTTP/1.1 400 Bad Request")) }) }) }) Context("UpsertTcpRouteMappings", func() { var ( err error tcpRouteMapping1 db.TcpRouteMapping tcpRouteMapping2 db.TcpRouteMapping ) BeforeEach(func() { tcpRouteMapping1 = db.NewTcpRouteMapping("router-group-guid-001", 52000, "1.2.3.4", 60000) tcpRouteMapping2 = db.NewTcpRouteMapping("router-group-guid-001", 52001, "1.2.3.5", 60001) }) JustBeforeEach(func() { err = client.UpsertTcpRouteMappings([]db.TcpRouteMapping{tcpRouteMapping1, tcpRouteMapping2}) }) Context("when the server returns a valid response", func() { BeforeEach(func() { server.AppendHandlers( ghttp.VerifyRequest("POST", TCP_CREATE_ROUTES_API_URL), ) }) It("sends an Upsert request to the server", func() {
log, err := ioutil.ReadAll(stdout) Expect(err).NotTo(HaveOccurred()) Expect(log).To(ContainSubstring("EVENT: ")) Expect(log).To(ContainSubstring(string(expectedJSON))) }) Context("When the event is unmarshalled successfully", func() { It("returns the raw event", func() { rawEvent := sse.Event{ ID: "1", Name: "Test", Data: []byte(`{"route": {"router_group_guid": "rguid1", "port":52000}, "backend_port":60000,"backend_ip":"1.1.1.1"}`), Retry: 1, } tcpMapping := db.NewTcpRouteMapping("rguid1", 52000, "1.1.1.1", 60000) expectedEvent := routing_api.TcpEvent{ TcpRouteMapping: tcpMapping, Action: "Test", } fakeRawEventSource.NextReturns(rawEvent, nil) event, err := tcpEventSource.Next() Expect(err).ToNot(HaveOccurred()) Expect(event).To(Equal(expectedEvent)) }) }) Context("When the event has invalid json", func() { It("returns the error", func() { rawEvent := sse.Event{
It("returns a key not found error if the key does not exists", func() { err := etcd.DeleteRoute(route) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("The specified route could not be found.")) }) }) }) }) Describe("Tcp Mappings", func() { var ( tcpMapping db.TcpRouteMapping ) BeforeEach(func() { tcpMapping = db.NewTcpRouteMapping("router-group-guid-001", 52000, "1.2.3.4", 60000) }) Describe("SaveTcpRouteMapping", func() { It("Creates a mapping if none exist", func() { err := etcd.SaveTcpRouteMapping(tcpMapping) Expect(err).NotTo(HaveOccurred()) key := fmt.Sprintf("%s/%s/%d/%s:%d", db.TCP_MAPPING_BASE_KEY, "router-group-guid-001", 52000, "1.2.3.4", 60000) node, err := etcdClient.Get(key) Expect(err).NotTo(HaveOccurred()) Expect(node.Value).To(MatchJSON(`{ "route": {"router_group_guid":"router-group-guid-001", "external_port":52000}, "host_ip": "1.2.3.4", "host_port": 60000
tcpRouteMapping1 db.TcpRouteMapping ) BeforeEach(func() { etcd, err = db.NewETCD(etcdRunner.NodeURLS(), 10) Expect(err).NotTo(HaveOccurred()) etcd.Connect() route = db.Route{ Route: "post_here", Port: 7000, IP: "1.2.3.4", TTL: 50, LogGuid: "my-guid", } tcpRouteMapping1 = db.NewTcpRouteMapping("router-group-guid-002", 52002, "2.3.4.5", 60002) }) AfterEach(func() { etcd.Disconnect() }) Describe("Http Routes", func() { Describe("ReadRoutes", func() { It("Returns a empty list of routes", func() { routes, err := etcd.ReadRoutes() Expect(err).NotTo(HaveOccurred()) Expect(routes).To(Equal([]db.Route{})) })