@@ -32,6 +32,7 @@ func TestMiddlewareMeasure(t *testing.T) {
32
32
mrep .On ("StatusCode" ).Once ().Return (418 )
33
33
mrep .On ("Method" ).Once ().Return ("PATCH" )
34
34
mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
35
+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
35
36
36
37
// Recorder mocks.
37
38
expProps := metrics.HTTPProperties {Service : "svc1" , ID : "test01" }
@@ -44,6 +45,35 @@ func TestMiddlewareMeasure(t *testing.T) {
44
45
},
45
46
},
46
47
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
+
47
77
"Without having handler ID, it should measure the metrics using the request path." : {
48
78
handlerID : "" ,
49
79
config : func () middleware.Config {
@@ -56,6 +86,7 @@ func TestMiddlewareMeasure(t *testing.T) {
56
86
mrep .On ("StatusCode" ).Once ().Return (418 )
57
87
mrep .On ("Method" ).Once ().Return ("PATCH" )
58
88
mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
89
+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
59
90
60
91
// Recorder mocks.
61
92
expRepProps := metrics.HTTPReqProperties {ID : "/test/01" , Method : "PATCH" , Code : "418" }
@@ -80,6 +111,7 @@ func TestMiddlewareMeasure(t *testing.T) {
80
111
mrep .On ("StatusCode" ).Once ().Return (418 )
81
112
mrep .On ("Method" ).Once ().Return ("PATCH" )
82
113
mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
114
+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
83
115
84
116
// Recorder mocks.
85
117
expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "4xx" }
@@ -104,6 +136,7 @@ func TestMiddlewareMeasure(t *testing.T) {
104
136
mrep .On ("StatusCode" ).Once ().Return (418 )
105
137
mrep .On ("Method" ).Once ().Return ("PATCH" )
106
138
mrep .On ("BytesWritten" ).Once ().Return (int64 (42 ))
139
+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
107
140
108
141
// Recorder mocks.
109
142
expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "418" }
@@ -125,6 +158,7 @@ func TestMiddlewareMeasure(t *testing.T) {
125
158
mrep .On ("Context" ).Once ().Return (context .TODO ())
126
159
mrep .On ("StatusCode" ).Once ().Return (418 )
127
160
mrep .On ("Method" ).Once ().Return ("PATCH" )
161
+ mrep .On ("URLPath" ).Once ().Return ("/test/01" )
128
162
129
163
// Recorder mocks.
130
164
expRepProps := metrics.HTTPReqProperties {ID : "test01" , Method : "PATCH" , Code : "418" }
0 commit comments