github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/metric/counter_test.go (about) 1 package metric_test 2 3 import ( 4 . "github.com/pf-qiu/concourse/v6/atc/metric" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("Counter", func() { 11 var counter *Counter 12 13 BeforeEach(func() { 14 counter = &Counter{} 15 }) 16 17 Context("when incremented", func() { 18 It("returns incremented value", func() { 19 Expect(counter.Delta()).To(Equal(float64(0))) 20 21 counter.Inc() 22 counter.Inc() 23 counter.Inc() 24 25 Expect(counter.Delta()).To(Equal(float64(3))) 26 }) 27 }) 28 29 Context("when incremented by a value", func() { 30 It("returns the incremented value", func() { 31 Expect(counter.Delta()).To(Equal(float64(0))) 32 33 counter.IncDelta(3) 34 35 Expect(counter.Delta()).To(Equal(float64(3))) 36 }) 37 }) 38 39 Context("when current value is requested", func() { 40 It("starts counting from 0", func() { 41 counter.Inc() 42 counter.Inc() 43 counter.Inc() 44 45 Expect(counter.Delta()).To(Equal(float64(3))) 46 Expect(counter.Delta()).To(Equal(float64(0))) 47 }) 48 }) 49 })