"encoding/json" "time" ) var _ = Describe("RouteRegistry", func() { var r *RouteRegistry var messageBus *fakeyagnats.FakeNATSConn var reporter *fakes.FakeRouteReporter var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint var configObj *config.Config BeforeEach(func() { configObj = config.DefaultConfig() configObj.PruneStaleDropletsInterval = 50 * time.Millisecond configObj.DropletStaleThreshold = 10 * time.Millisecond messageBus = fakeyagnats.Connect() reporter = new(fakes.FakeRouteReporter) r = NewRouteRegistry(configObj, messageBus, reporter) fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234, "id1", map[string]string{ "runtime": "ruby18", "framework": "sinatra", }, -1, "") barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321, "id2", map[string]string{ "runtime": "javascript",
Context("When the token fetcher returns an error", func() { BeforeEach(func() { tokenFetcher.FetchTokenReturns(nil, errors.New("token fetcher error")) }) It("returns an error", func() { err := fetcher.FetchRoutes() Expect(err).To(HaveOccurred()) Expect(registry.RegisterCallCount()).To(Equal(0)) }) }) }) Describe(".StartFetchCycle", func() { BeforeEach(func() { cfg.PruneStaleDropletsInterval = 10 * time.Millisecond fetcher = NewRouteFetcher(logger, tokenFetcher, registry, cfg, client, retryInterval) tokenFetcher.FetchTokenReturns(token, nil) client.RoutesReturns(response, nil) }) It("periodically fetches routes", func() { received := make(chan struct{}) client.RoutesStub = func() ([]db.Route, error) { received <- struct{}{} return []db.Route{}, nil }