Ω(err).ShouldNot(HaveOccurred()) Ω(value.TTL).Should(BeNumerically("==", ttl)) var freshnessTimestamp models.FreshnessTimestamp json.Unmarshal(value.Value, &freshnessTimestamp) Ω(freshnessTimestamp.Timestamp).Should(BeNumerically("==", 100)) Ω(value.Key).Should(Equal(key)) }) }) } Context("the actual state", func() { bumpingFreshness("/hm/v1"+conf.ActualFreshnessKey, conf.ActualFreshnessTTL(), Store.BumpActualFreshness) Context("revoking actual state freshness", func() { BeforeEach(func() { store.BumpActualFreshness(time.Unix(100, 0)) }) It("should no longer be fresh", func() { fresh, err := store.IsActualStateFresh(time.Unix(130, 0)) Ω(err).ShouldNot(HaveOccurred()) Ω(fresh).Should(BeTrue()) store.RevokeActualFreshness() fresh, err = store.IsActualStateFresh(time.Unix(130, 0)) Ω(err).ShouldNot(HaveOccurred())
conf *config.Config freshByTime time.Time usageTracker *fakeusagetracker.FakeUsageTracker metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant ) BeforeEach(func() { var err error conf, err = config.DefaultConfig() Ω(err).ShouldNot(HaveOccurred()) timeProvider = faketimeprovider.New(time.Unix(100, 0)) timeProvider.ProvideFakeChannels = true freshByTime = time.Unix(int64(100+conf.ActualFreshnessTTL()), 0) dea = NewDeaFixture() app = NewAppFixture() anotherApp = NewAppFixture() anotherApp.DeaGuid = app.DeaGuid storeAdapter = fakestoreadapter.New() store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger()) messageBus = fakeyagnats.New() logger = fakelogger.NewFakeLogger() usageTracker = fakeusagetracker.New() usageTracker.UsageToReturn = 0.7 metricsAccountant = fakemetricsaccountant.New()
logger *fakelogger.FakeLogger conf *config.Config freshByTime time.Time usageTracker *fakemetricsaccountant.FakeUsageTracker metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant ) BeforeEach(func() { var err error conf, err = config.DefaultConfig() Expect(err).NotTo(HaveOccurred()) clock = fakeclock.NewFakeClock(time.Unix(100, 0)) freshByTime = time.Unix(int64(100+conf.ActualFreshnessTTL()), 0) dea = NewDeaFixture() app = NewAppFixture() anotherApp = NewAppFixture() anotherApp.DeaGuid = app.DeaGuid storeAdapter = fakestoreadapter.New() store = &fakestore.FakeStore{} messageBus = fakeyagnats.Connect() logger = fakelogger.NewFakeLogger() usageTracker = &fakemetricsaccountant.FakeUsageTracker{} usageTracker.MeasureUsageReturns(0.7, 0) metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{} })
timeProvider *faketimeprovider.FakeTimeProvider dea appfixture.DeaFixture app appfixture.AppFixture conf *config.Config metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant ) BeforeEach(func() { messageBus = fakeyagnats.New() dea = appfixture.NewDeaFixture() app = dea.GetApp(0) conf, _ = config.DefaultConfig() metricsAccountant = fakemetricsaccountant.New() timeProvider = &faketimeprovider.FakeTimeProvider{ TimeToProvide: time.Unix(int64(10+conf.ActualFreshnessTTL()), 0), } storeAdapter = fakestoreadapter.New() store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger()) sender = New(store, metricsAccountant, conf, messageBus, timeProvider, fakelogger.NewFakeLogger()) store.BumpActualFreshness(time.Unix(10, 0)) store.BumpDesiredFreshness(time.Unix(10, 0)) }) Context("when the sender fails to pull messages out of the start queue", func() { BeforeEach(func() { storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("start", errors.New("oops")) }) It("should return an error and not send any messages", func() {
messageBus *fakeyagnats.FakeNATSConn timeProvider *fakeclock.FakeClock dea appfixture.DeaFixture app appfixture.AppFixture conf *config.Config metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant ) BeforeEach(func() { messageBus = fakeyagnats.Connect() dea = appfixture.NewDeaFixture() app = dea.GetApp(0) conf, _ = config.DefaultConfig() metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{} timeProvider = fakeclock.NewFakeClock(time.Unix(int64(10+conf.ActualFreshnessTTL()), 0)) storeAdapter = fakestoreadapter.New() store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger()) sender = New(store, metricsAccountant, conf, messageBus, fakelogger.NewFakeLogger()) store.BumpActualFreshness(time.Unix(10, 0)) store.BumpDesiredFreshness(time.Unix(10, 0)) }) Context("when the sender fails to pull messages out of the start queue", func() { BeforeEach(func() { storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("start", errors.New("oops")) }) It("should return an error and not send any messages", func() { err := sender.Send(timeProvider)