@@ -32,6 +32,7 @@ func TestMiddlewareMeasure(t *testing.T) {
3232 mrep .On ("StatusCode" ).Once ().Return (418 )
3333 mrep .On ("Method" ).Once ().Return ("PATCH" )
3434 mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
35+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
3536
3637 // Recorder mocks.
3738 expProps := metrics.HTTPProperties {Service : "svc1" , ID : "test01" }
@@ -44,6 +45,35 @@ func TestMiddlewareMeasure(t *testing.T) {
4445 },
4546 },
4647
48+ "Having an ignored path in the config, it should not measure the metrics for the ignored path." : {
49+ handlerID : "test01" ,
50+ config : func () middleware.Config {
51+ return middleware.Config {
52+ Service : "svc1" ,
53+ IgnoredPaths : map [string ]struct {}{
54+ "/ignored" : {},
55+ },
56+ }
57+ },
58+ mock : func (mrec * mockmetrics.Recorder , mrep * mockmiddleware.Reporter ) {
59+ // Reporter mocks.
60+ mrep .On ("Context" ).Once ().Return (context .TODO ())
61+ mrep .AssertNotCalled (t , "StatusCode" )
62+ mrep .AssertNotCalled (t , "Method" )
63+ mrep .AssertNotCalled (t , "BytesWritten" )
64+ mrep .On ("URLPath" ).Once ().Return ("/ignored" )
65+
66+ // Recorder mocks.
67+ expProps := metrics.HTTPProperties {Service : "svc1" , ID : "test01" }
68+ expRepProps := metrics.HTTPReqProperties {Service : "svc1" , ID : "test01" , Method : "PATCH" , Code : "418" }
69+
70+ mrec .On ("AddInflightRequests" , mock .Anything , expProps , 1 ).Once ()
71+ mrec .On ("AddInflightRequests" , mock .Anything , expProps , - 1 ).Once ()
72+ mrec .AssertNotCalled (t , "ObserveHTTPRequestDuration" , mock .Anything , expRepProps , mock .Anything )
73+ mrec .AssertNotCalled (t , "ObserveHTTPResponseSize" , mock .Anything , expRepProps , int64 (42 ))
74+ },
75+ },
76+
4777 "Without having handler ID, it should measure the metrics using the request path." : {
4878 handlerID : "" ,
4979 config : func () middleware.Config {
@@ -56,6 +86,7 @@ func TestMiddlewareMeasure(t *testing.T) {
5686 mrep .On ("StatusCode" ).Once ().Return (418 )
5787 mrep .On ("Method" ).Once ().Return ("PATCH" )
5888 mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
89+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
5990
6091 // Recorder mocks.
6192 expRepProps := metrics.HTTPReqProperties {ID : "/test/01" , Method : "PATCH" , Code : "418" }
@@ -80,6 +111,7 @@ func TestMiddlewareMeasure(t *testing.T) {
80111 mrep .On ("StatusCode" ).Once ().Return (418 )
81112 mrep .On ("Method" ).Once ().Return ("PATCH" )
82113 mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
114+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
83115
84116 // Recorder mocks.
85117 expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "4xx" }
@@ -104,6 +136,7 @@ func TestMiddlewareMeasure(t *testing.T) {
104136 mrep .On ("StatusCode" ).Once ().Return (418 )
105137 mrep .On ("Method" ).Once ().Return ("PATCH" )
106138 mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
139+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
107140
108141 // Recorder mocks.
109142 expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "418" }
@@ -125,6 +158,7 @@ func TestMiddlewareMeasure(t *testing.T) {
125158 mrep .On ("Context" ).Once ().Return (context .TODO ())
126159 mrep .On ("StatusCode" ).Once ().Return (418 )
127160 mrep .On ("Method" ).Once ().Return ("PATCH" )
161+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
128162
129163 // Recorder mocks.
130164 expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "418" }
0 commit comments