"github.com/cloudfoundry/yagnats/fakeyagnats" "encoding/json" "time" ) var _ = Describe("RouteRegistry", func() { var r *RouteRegistry var messageBus *fakeyagnats.FakeYagnats 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.New() r = NewRouteRegistry(configObj, messageBus) fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234, "id1", map[string]string{ "runtime": "ruby18", "framework": "sinatra", }) barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321, "id2", map[string]string{ "runtime": "javascript", "framework": "node", })
client *fake_routing_api.FakeClient token *schema.Token response []db.Route process ifrit.Process eventChannel chan routing_api.Event errorChannel chan error clock *fakeclock.FakeClock ) BeforeEach(func() { logger = lagertest.NewTestLogger("test") cfg = config.DefaultConfig() cfg.PruneStaleDropletsInterval = 2 * time.Second retryInterval := 0 uaaClient = &testUaaClient.FakeClient{} registry = &testRegistry.FakeRegistryInterface{} token = &schema.Token{ AccessToken: "access_token", ExpiresIn: 5, } client = &fake_routing_api.FakeClient{} eventChannel = make(chan routing_api.Event) errorChannel = make(chan error) eventSource := fake_routing_api.FakeEventSource{} client.SubscribeToEventsWithMaxRetriesReturns(&eventSource, nil)
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 }