github.com/kaituanwang/hyperledger@v2.0.1+incompatible/core/ledger/util/couchdb/metrics_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 SPDX-License-Identifier: Apache-2.0 4 */ 5 6 package couchdb 7 8 import ( 9 "context" 10 "net/http" 11 "net/url" 12 "testing" 13 14 "github.com/hyperledger/fabric/common/metrics/disabled" 15 "github.com/hyperledger/fabric/common/metrics/metricsfakes" 16 . "github.com/onsi/gomega" 17 ) 18 19 func TestAPIProcessTimeMetric(t *testing.T) { 20 gt := NewGomegaWithT(t) 21 fakeHistogram := &metricsfakes.Histogram{} 22 fakeHistogram.WithReturns(fakeHistogram) 23 24 // create a new couch instance 25 config := testConfig() 26 config.MaxRetries = 0 27 couchInstance, err := CreateCouchInstance(config, &disabled.Provider{}) 28 gt.Expect(err).NotTo(HaveOccurred(), "Error when trying to create couch instance") 29 30 couchInstance.stats = &stats{ 31 apiProcessingTime: fakeHistogram, 32 } 33 34 url, err := url.Parse("http://locahost:0") 35 gt.Expect(err).NotTo(HaveOccurred(), "Error when trying to parse URL") 36 37 couchInstance.handleRequest(context.Background(), http.MethodGet, "db_name", "function_name", url, nil, "", "", 0, true, nil) 38 gt.Expect(fakeHistogram.ObserveCallCount()).To(Equal(1)) 39 gt.Expect(fakeHistogram.ObserveArgsForCall(0)).NotTo(BeZero()) 40 gt.Expect(fakeHistogram.WithArgsForCall(0)).To(Equal([]string{ 41 "database", "db_name", 42 "function_name", "function_name", 43 "result", "0", 44 })) 45 }