github.com/anjalikarhana/fabric@v2.1.1+incompatible/orderer/common/broadcast/metrics_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package broadcast_test 8 9 import ( 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 13 "github.com/hyperledger/fabric/orderer/common/broadcast" 14 "github.com/hyperledger/fabric/orderer/common/broadcast/mock" 15 ) 16 17 var _ = Describe("Metrics", func() { 18 var ( 19 fakeProvider *mock.MetricsProvider 20 ) 21 22 BeforeEach(func() { 23 fakeProvider = &mock.MetricsProvider{} 24 fakeProvider.NewHistogramReturns(&mock.MetricsHistogram{}) 25 fakeProvider.NewCounterReturns(&mock.MetricsCounter{}) 26 }) 27 28 It("uses the provider to initialize all fields", func() { 29 metrics := broadcast.NewMetrics(fakeProvider) 30 Expect(metrics).NotTo(BeNil()) 31 Expect(metrics.ValidateDuration).To(Equal(&mock.MetricsHistogram{})) 32 Expect(metrics.EnqueueDuration).To(Equal(&mock.MetricsHistogram{})) 33 Expect(metrics.ProcessedCount).To(Equal(&mock.MetricsCounter{})) 34 35 Expect(fakeProvider.NewHistogramCallCount()).To(Equal(2)) 36 Expect(fakeProvider.NewCounterCallCount()).To(Equal(1)) 37 }) 38 })