@@ -69,49 +69,33 @@ func TestMiddlewareWrapsFirstToLast(t *testing.T) {
6969}
7070
7171func TestMiddlewareAPI (t * testing.T ) {
72- var (
73- his = prometheus .NewHistogram (prometheus.HistogramOpts {Name : "test_histogram" })
74- sum = prometheus .NewSummary (prometheus.SummaryOpts {Name : "test_summary" })
75- gauge = prometheus .NewGauge (prometheus.GaugeOpts {Name : "test_gauge" })
76- )
77-
78- obs := []prometheus.Observer {
79- his ,
80- sum ,
81- prometheus .ObserverFunc (gauge .Set ),
82- }
83-
8472 client := * http .DefaultClient
8573 client .Timeout = 300 * time .Millisecond
8674
8775 inFlightGauge := prometheus .NewGauge (prometheus.GaugeOpts {Name : "inFlight" })
8876 inFlight := func (r * http.Request , next Middleware ) (* http.Response , error ) {
89- log .Println ("1st" )
9077 inFlightGauge .Inc ()
9178
9279 resp , err := next (r )
9380
9481 inFlightGauge .Dec ()
9582
96- log .Println ("last" )
9783 return resp , err
9884 }
9985
10086 counter := prometheus .NewCounter (prometheus.CounterOpts {Name : "test_counter" })
101- bytesSent := func (req * http.Request , next Middleware ) (* http.Response , error ) {
87+ addFortyTwo := func (req * http.Request , next Middleware ) (* http.Response , error ) {
10288 counter .Add (42 )
103- log .Println ("2nd" )
104- // counter.Add(float64(req.ContentLength))
10589
10690 return next (req )
10791 }
10892
10993 logging := func (req * http.Request , next Middleware ) (* http.Response , error ) {
110- log .Println ("3rd " )
94+ log .Println ("log something interesting " )
11195 return next (req )
11296 }
11397
114- promclient , err := NewClient (SetClient (client ), SetObservers ( obs ), SetMiddleware (inFlight , bytesSent , logging ))
98+ promclient , err := NewClient (SetClient (client ), SetMiddleware (inFlight , addFortyTwo , logging ))
11599 if err != nil {
116100 t .Fatalf ("%v" , err )
117101 }
0 commit comments