@@ -20,6 +20,7 @@ fn resource(path: &str) -> WebmachineRequest {
20
20
WebmachineRequest {
21
21
request_path : path. to_string ( ) ,
22
22
base_path : "/" . to_string ( ) ,
23
+ path_vars : Default :: default ( ) ,
23
24
method : "GET" . to_string ( ) ,
24
25
headers : HashMap :: new ( ) ,
25
26
body : None ,
@@ -34,16 +35,61 @@ fn path_matcher_test() {
34
35
"/" => WebmachineResource :: default ( ) ,
35
36
"/path1" => WebmachineResource :: default ( ) ,
36
37
"/path2" => WebmachineResource :: default ( ) ,
37
- "/path1/path3" => WebmachineResource :: default ( )
38
+ "/path1/path3" => WebmachineResource :: default ( ) ,
39
+ "/path2/{id}" => WebmachineResource :: default ( ) ,
40
+ "/path2/{id}/path3" => WebmachineResource :: default ( )
38
41
}
39
42
} ;
40
- expect ! ( dispatcher. match_paths( & resource( "/path1" ) ) ) . to ( be_equal_to ( vec ! [ "/" , "/path1" ] ) ) ;
41
- expect ! ( dispatcher. match_paths( & resource( "/path1/" ) ) ) . to ( be_equal_to ( vec ! [ "/" , "/path1" ] ) ) ;
42
- expect ! ( dispatcher. match_paths( & resource( "/path1/path3" ) ) ) . to ( be_equal_to ( vec ! [ "/" , "/path1" , "/path1/path3" ] ) ) ;
43
- expect ! ( dispatcher. match_paths( & resource( "/path1/path3/path4" ) ) ) . to ( be_equal_to ( vec ! [ "/" , "/path1" , "/path1/path3" ] ) ) ;
44
- expect ! ( dispatcher. match_paths( & resource( "/path1/other" ) ) ) . to ( be_equal_to ( vec ! [ "/" , "/path1" ] ) ) ;
45
- expect ! ( dispatcher. match_paths( & resource( "/path12" ) ) ) . to ( be_equal_to ( vec ! [ "/" ] ) ) ;
46
- expect ! ( dispatcher. match_paths( & resource( "/" ) ) ) . to ( be_equal_to ( vec ! [ "/" ] ) ) ;
43
+
44
+ expect ! ( dispatcher. match_paths( & resource( "/path1" ) ) ) . to ( be_equal_to ( vec ! [
45
+ ( "/" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) ] ) ,
46
+ ( "/path1" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) ] ) ,
47
+ ] ) ) ;
48
+ expect ! ( dispatcher. match_paths( & resource( "/path1/" ) ) ) . to ( be_equal_to ( vec ! [
49
+ ( "/" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) ] ) ,
50
+ ( "/path1" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) ] ) ]
51
+ ) ) ;
52
+ expect ! ( dispatcher. match_paths( & resource( "/path1/path3" ) ) ) . to ( be_equal_to ( vec ! [
53
+ ( "/" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) ] ) ,
54
+ ( "/path1" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) ] ) ,
55
+ ( "/path1/path3" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) ] )
56
+ ] ) ) ;
57
+ expect ! ( dispatcher. match_paths( & resource( "/path1/path3/path4" ) ) ) . to ( be_equal_to ( vec ! [
58
+ ( "/" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) , ( "path4" . to_string( ) , None ) ] ) ,
59
+ ( "/path1" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) , ( "path4" . to_string( ) , None ) ] ) ,
60
+ ( "/path1/path3" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) , ( "path4" . to_string( ) , None ) ] )
61
+ ] ) ) ;
62
+ expect ! ( dispatcher. match_paths( & resource( "/path1/other" ) ) ) . to ( be_equal_to ( vec ! [
63
+ ( "/" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "other" . to_string( ) , None ) ] ) ,
64
+ ( "/path1" . to_string( ) , vec![ ( "path1" . to_string( ) , None ) , ( "other" . to_string( ) , None ) ] )
65
+ ] ) ) ;
66
+ expect ! ( dispatcher. match_paths( & resource( "/path12" ) ) ) . to ( be_equal_to ( vec ! [
67
+ ( "/" . to_string( ) , vec![ ( "path12" . to_string( ) , None ) ] )
68
+ ] ) ) ;
69
+ expect ! ( dispatcher. match_paths( & resource( "/" ) ) ) . to ( be_equal_to ( vec ! [
70
+ ( "/" . to_string( ) , vec![ ] )
71
+ ] ) ) ;
72
+
73
+ expect ! ( dispatcher. match_paths( & resource( "/path2" ) ) ) . to ( be_equal_to ( vec ! [
74
+ ( "/" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) ] ) ,
75
+ ( "/path2" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) ] ) ,
76
+ ] ) ) ;
77
+ expect ! ( dispatcher. match_paths( & resource( "/path2/1000" ) ) ) . to ( be_equal_to ( vec ! [
78
+ ( "/" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) ] ) ,
79
+ ( "/path2" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) ] ) ,
80
+ ( "/path2/{id}" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , Some ( "id" . to_string( ) ) ) ] )
81
+ ] ) ) ;
82
+ expect ! ( dispatcher. match_paths( & resource( "/path2/1000/path3" ) ) ) . to ( be_equal_to ( vec ! [
83
+ ( "/" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) ] ) ,
84
+ ( "/path2" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) , ( "path3" . to_string( ) , None ) ] ) ,
85
+ ( "/path2/{id}" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , Some ( "id" . to_string( ) ) ) , ( "path3" . to_string( ) , None ) ] ) ,
86
+ ( "/path2/{id}/path3" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , Some ( "id" . to_string( ) ) ) , ( "path3" . to_string( ) , None ) ] )
87
+ ] ) ) ;
88
+ expect ! ( dispatcher. match_paths( & resource( "/path2/1000/other" ) ) ) . to ( be_equal_to ( vec ! [
89
+ ( "/" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) , ( "other" . to_string( ) , None ) ] ) ,
90
+ ( "/path2" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , None ) , ( "other" . to_string( ) , None ) ] ) ,
91
+ ( "/path2/{id}" . to_string( ) , vec![ ( "path2" . to_string( ) , None ) , ( "1000" . to_string( ) , Some ( "id" . to_string( ) ) ) , ( "other" . to_string( ) , None ) ] )
92
+ ] ) ) ;
47
93
}
48
94
49
95
#[ test]
@@ -79,42 +125,54 @@ async fn execute_state_machine_returns_503_if_resource_indicates_not_available()
79
125
#[ test]
80
126
fn update_paths_for_resource_test_with_root ( ) {
81
127
let mut request = WebmachineRequest :: default ( ) ;
82
- update_paths_for_resource ( & mut request, "/" ) ;
83
- expect ( request. request_path ) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
84
- expect ( request. base_path ) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
128
+ update_paths_for_resource ( & mut request, "/" , & vec ! [ ] ) ;
129
+ expect ! ( request. request_path) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
130
+ expect ! ( request. base_path) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
85
131
}
86
132
87
133
#[ test]
88
134
fn update_paths_for_resource_test_with_subpath ( ) {
89
135
let mut request = WebmachineRequest {
90
136
request_path : "/subpath" . to_string ( ) ,
91
- ..WebmachineRequest :: default ( )
137
+ .. WebmachineRequest :: default ( )
92
138
} ;
93
- update_paths_for_resource ( & mut request, "/" ) ;
94
- expect ( request. request_path ) . to ( be_equal_to ( "/subpath" . to_string ( ) ) ) ;
95
- expect ( request. base_path ) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
139
+ update_paths_for_resource ( & mut request, "/" , & vec ! [ ] ) ;
140
+ expect ! ( request. request_path) . to ( be_equal_to ( "/subpath" . to_string ( ) ) ) ;
141
+ expect ! ( request. base_path) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
96
142
}
97
143
98
144
#[ test]
99
145
fn update_paths_for_resource_on_path ( ) {
100
146
let mut request = WebmachineRequest {
101
147
request_path : "/path" . to_string ( ) ,
102
- ..WebmachineRequest :: default ( )
148
+ .. WebmachineRequest :: default ( )
103
149
} ;
104
- update_paths_for_resource ( & mut request, "/path" ) ;
105
- expect ( request. request_path ) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
106
- expect ( request. base_path ) . to ( be_equal_to ( "/path" . to_string ( ) ) ) ;
150
+ update_paths_for_resource ( & mut request, "/path" , & vec ! [ ] ) ;
151
+ expect ! ( request. request_path) . to ( be_equal_to ( "/" . to_string ( ) ) ) ;
152
+ expect ! ( request. base_path) . to ( be_equal_to ( "/path" . to_string ( ) ) ) ;
107
153
}
108
154
109
155
#[ test]
110
156
fn update_paths_for_resource_on_path_with_subpath ( ) {
111
157
let mut request = WebmachineRequest {
112
158
request_path : "/path/path2" . to_string ( ) ,
113
- ..WebmachineRequest :: default ( )
159
+ .. WebmachineRequest :: default ( )
160
+ } ;
161
+ update_paths_for_resource ( & mut request, "/path" , & vec ! [ ] ) ;
162
+ expect ! ( request. request_path) . to ( be_equal_to ( "/path2" . to_string ( ) ) ) ;
163
+ expect ! ( request. base_path) . to ( be_equal_to ( "/path" . to_string ( ) ) ) ;
164
+ }
165
+
166
+ #[ test]
167
+ fn update_paths_for_resource_on_path_with_mapped_parts ( ) {
168
+ let mut request = WebmachineRequest {
169
+ request_path : "/path/1000" . to_string ( ) ,
170
+ .. WebmachineRequest :: default ( )
114
171
} ;
115
- update_paths_for_resource ( & mut request, "/path" ) ;
116
- expect ( request. request_path ) . to ( be_equal_to ( "/path2" . to_string ( ) ) ) ;
117
- expect ( request. base_path ) . to ( be_equal_to ( "/path" . to_string ( ) ) ) ;
172
+ update_paths_for_resource ( & mut request, "/path" , & vec ! [ ( "1000" . to_string( ) , Some ( "id" . to_string( ) ) ) ] ) ;
173
+ expect ! ( request. request_path) . to ( be_equal_to ( "/1000" . to_string ( ) ) ) ;
174
+ expect ! ( request. base_path) . to ( be_equal_to ( "/path" . to_string ( ) ) ) ;
175
+ expect ! ( request. path_vars) . to ( be_equal_to ( hashmap ! { "id" . to_string( ) => "1000" . to_string( ) } ) ) ;
118
176
}
119
177
120
178
#[ tokio:: test]
0 commit comments