예제 #1
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("logs with noaa repository", func() {
	var (
		fakeNoaaConsumer   *testapi.FakeNoaaConsumer
		config             core_config.ReadWriter
		fakeTokenRefresher *testapi.FakeAuthenticationRepository
		repo               api.LogsNoaaRepository
	)

	BeforeEach(func() {
		fakeNoaaConsumer = &testapi.FakeNoaaConsumer{}
		config = testconfig.NewRepositoryWithDefaults()
		config.SetLoggregatorEndpoint("loggregator.test.com")
		config.SetDopplerEndpoint("doppler.test.com")
		config.SetAccessToken("the-access-token")
		fakeTokenRefresher = &testapi.FakeAuthenticationRepository{}
		repo = api.NewLogsNoaaRepository(config, fakeNoaaConsumer, fakeTokenRefresher)
	})

	Describe("RecentLogsFor", func() {

		It("refreshes token and get metric once more if token has expired.", func() {
			fakeNoaaConsumer.RecentLogsReturns([]*events.LogMessage{},
				noaa_errors.NewUnauthorizedError("Unauthorized token"))

			repo.RecentLogsFor("app-guid")
			Ω(fakeTokenRefresher.RefreshTokenCalled).To(BeTrue())
			Ω(fakeNoaaConsumer.RecentLogsCallCount()).To(Equal(2))
	. "github.com/onsi/gomega"
)

var _ = Describe("loggregator logs repository", func() {
	var (
		fakeConsumer       *testapi.FakeLoggregatorConsumer
		logsRepo           OldLogsRepository
		configRepo         core_config.ReadWriter
		fakeTokenRefresher *testapi.FakeAuthenticationRepository
	)

	BeforeEach(func() {
		BufferTime = 1 * time.Millisecond
		fakeConsumer = testapi.NewFakeLoggregatorConsumer()
		configRepo = testconfig.NewRepositoryWithDefaults()
		configRepo.SetLoggregatorEndpoint("loggregator-server.test.com")
		configRepo.SetAccessToken("the-access-token")
		fakeTokenRefresher = &testapi.FakeAuthenticationRepository{}
	})

	JustBeforeEach(func() {
		logsRepo = NewLoggregatorLogsRepository(configRepo, fakeConsumer, fakeTokenRefresher)
	})

	Describe("RecentLogsFor", func() {
		Context("when a noaa_errors.UnauthorizedError occurs", func() {
			BeforeEach(func() {
				fakeConsumer.RecentReturns.Err = []error{
					noaa_errors.NewUnauthorizedError("i'm sorry dave"),
					nil,
				}