Example #1
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Count", func() {
	var count database.Aggregator

	BeforeEach(func() {
		count = aggregators.NewCount()
	})

	It("Sums all the account values", func() {
		accs := []*transaction.Account{
			{
				Name:  "some-name-1",
				Value: 1234,
			},
			{
				Name:  "some-name-2",
				Value: 5678,
			},
		}

		Expect(count.Aggregate(accs)).To(Equal("2"))
	})

	It("registers itself with the aggregator store", func() {
		Expect(aggregators.Store()).To(HaveKey("count"))
	})

})
Example #2
0
)

var _ = Describe("Sum", func() {

	var sum database.Aggregator

	BeforeEach(func() {
		sum = aggregators.NewSum()
	})

	It("Sums all the account values", func() {
		accs := []*transaction.Account{
			{
				Name:  "some-name-1",
				Value: 1234,
			},
			{
				Name:  "some-name-2",
				Value: 5678,
			},
		}

		Expect(sum.Aggregate(accs)).To(Equal("$69.12"))
	})

	It("registers itself with the aggregator store", func() {
		Expect(aggregators.Store()).To(HaveKey("sum"))
	})

})
Example #3
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Store", func() {
	var someAgg aggregators.AggregatorFunc

	BeforeEach(func() {
		someAgg = aggregators.AggregatorFunc(func([]*transaction.Account) string {
			return ""
		})
	})

	It("has a map of aggregators", func() {
		aggregators.AddToStore("some-agg-name", someAgg)
		Expect(aggregators.Store()).To(HaveKey("some-agg-name"))
	})

	It("panics if the same name is added twice", func() {
		aggregators.AddToStore("some-other-name", nil)
		Expect(func() { aggregators.AddToStore("some-other-name", nil) }).To(Panic())
	})

	Describe("Fetch()", func() {
		It("returns all the matching aggregators", func() {
			aggregators.AddToStore("agg-1", someAgg)
			aggregators.AddToStore("agg-2", someAgg)
			aggs, err := aggregators.Fetch("agg-1", "agg-2")

			Expect(err).ToNot(HaveOccurred())
			Expect(aggs).To(HaveLen(2))
Example #4
0
)

var _ = Describe("Mean", func() {

	var mean database.Aggregator

	BeforeEach(func() {
		mean = aggregators.NewMean()
	})

	It("returns the mean", func() {
		accs := []*transaction.Account{
			{
				Name:  "some-name-1",
				Value: 1000,
			},
			{
				Name:  "some-name-2",
				Value: 500,
			},
		}

		Expect(mean.Aggregate(accs)).To(Equal("$7.50"))
	})

	It("registers itself with the aggregator store", func() {
		Expect(aggregators.Store()).To(HaveKey("mean"))
	})

})
Example #5
0
func listAggregators(c *cli.Context) {
	for name := range aggregators.Store() {
		fmt.Println(name)
	}
}