@@ -93,15 +93,19 @@ mod tests {
9393 use http:: Method ;
9494 use std:: time:: Duration ;
9595
96- #[ test]
97- fn test_route_matching_all ( ) {
98- let route = Route {
99- host : None ,
100- method : None ,
101- path_prefix : String :: new ( ) ,
96+ fn test_route ( host : Option < & str > , method : Option < Method > , path : & str ) -> Route {
97+ Route {
98+ host : host. map ( String :: from) ,
99+ method,
100+ path_prefix : path. to_string ( ) ,
102101 limits : vec ! [ ] ,
103102 on_limit : ThrottleBehavior :: Delay ,
104- } ;
103+ }
104+ }
105+
106+ #[ test]
107+ fn test_route_matching_all ( ) {
108+ let route = test_route ( None , None , "" ) ;
105109
106110 let req = reqwest:: Client :: new ( )
107111 . get ( "https://example.com/test" )
@@ -113,13 +117,7 @@ mod tests {
113117
114118 #[ test]
115119 fn test_route_matching_host ( ) {
116- let route = Route {
117- host : Some ( "api.example.com" . to_string ( ) ) ,
118- method : None ,
119- path_prefix : String :: new ( ) ,
120- limits : vec ! [ ] ,
121- on_limit : ThrottleBehavior :: Delay ,
122- } ;
120+ let route = test_route ( Some ( "api.example.com" ) , None , "" ) ;
123121
124122 let req_match = reqwest:: Client :: new ( )
125123 . get ( "https://api.example.com/test" )
@@ -136,13 +134,7 @@ mod tests {
136134
137135 #[ test]
138136 fn test_route_matching_method ( ) {
139- let route = Route {
140- host : None ,
141- method : Some ( Method :: POST ) ,
142- path_prefix : String :: new ( ) ,
143- limits : vec ! [ ] ,
144- on_limit : ThrottleBehavior :: Delay ,
145- } ;
137+ let route = test_route ( None , Some ( Method :: POST ) , "" ) ;
146138
147139 let req_match = reqwest:: Client :: new ( )
148140 . post ( "https://example.com/test" )
@@ -159,13 +151,7 @@ mod tests {
159151
160152 #[ test]
161153 fn test_route_matching_path_prefix ( ) {
162- let route = Route {
163- host : None ,
164- method : None ,
165- path_prefix : "/api/v1" . to_string ( ) ,
166- limits : vec ! [ ] ,
167- on_limit : ThrottleBehavior :: Delay ,
168- } ;
154+ let route = test_route ( None , None , "/api/v1" ) ;
169155
170156 let req_match = reqwest:: Client :: new ( )
171157 . get ( "https://example.com/api/v1/users" )
@@ -182,13 +168,7 @@ mod tests {
182168
183169 #[ test]
184170 fn test_route_matching_path_segment_boundary ( ) {
185- let route = Route {
186- host : None ,
187- method : None ,
188- path_prefix : "/order" . to_string ( ) ,
189- limits : vec ! [ ] ,
190- on_limit : ThrottleBehavior :: Delay ,
191- } ;
171+ let route = test_route ( None , None , "/order" ) ;
192172
193173 // Should match: exact, with trailing slash, with sub-path
194174 let req_exact = reqwest:: Client :: new ( )
0 commit comments