Ejemplo n.º 1
0
func (repo *NoaaLogsRepository) RecentLogsFor(appGUID string) ([]Loggable, error) {
	logs, err := repo.consumer.RecentLogs(appGUID, repo.config.AccessToken())

	if err != nil {
		return loggableMessagesFromNoaaMessages(logs), err
	}
	return loggableMessagesFromNoaaMessages(noaa.SortRecent(logs)), err
}
Ejemplo n.º 2
0
func (l *logNoaaRepository) RecentLogsFor(appGuid string) ([]*events.LogMessage, error) {
	logs, err := l.consumer.RecentLogs(appGuid, l.config.AccessToken())

	switch err.(type) {
	case nil: // do nothing
	case *noaa_errors.UnauthorizedError:
		l.tokenRefresher.RefreshAuthToken()
		logs, err = l.consumer.RecentLogs(appGuid, l.config.AccessToken())
	default:
		return logs, err
	}

	return noaa.SortRecent(logs), err
}
Ejemplo n.º 3
0
func (repo *NoaaLogsRepository) RecentLogsFor(appGUID string) ([]Loggable, error) {
	logs, err := repo.consumer.RecentLogs(appGUID, repo.config.AccessToken())

	switch err.(type) {
	case nil: // do nothing
	case *noaa_errors.UnauthorizedError:
		_, _ = repo.tokenRefresher.RefreshAuthToken()
		return repo.RecentLogsFor(appGUID)
	default:
		return loggableMessagesFromNoaaMessages(logs), err
	}

	return loggableMessagesFromNoaaMessages(noaa.SortRecent(logs)), err
}
	"github.com/cloudfoundry/noaa"
	"github.com/cloudfoundry/noaa/events"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("SortRecent", func() {
	var messages []*events.LogMessage

	BeforeEach(func() {
		messages = []*events.LogMessage{createLogMessage("hello", 2), createLogMessage("konnichiha", 1)}
	})

	It("sorts messages", func() {
		sortedMessages := noaa.SortRecent(messages)

		Expect(*sortedMessages[0].Timestamp).To(Equal(int64(1)))
		Expect(*sortedMessages[1].Timestamp).To(Equal(int64(2)))
	})

	It("sorts using a stable algorithm", func() {
		messages = append(messages, createLogMessage("guten tag", 1))

		sortedMessages := noaa.SortRecent(messages)

		Expect(sortedMessages[0].GetMessage()).To(Equal([]byte("konnichiha")))
		Expect(sortedMessages[1].GetMessage()).To(Equal([]byte("guten tag")))
		Expect(sortedMessages[2].GetMessage()).To(Equal([]byte("hello")))
	})
})