@@ -65,110 +65,39 @@ pub struct ErroredExample {
6565impl TestExamplesOutput {
6666 pub fn from_project ( test_examples_input : TestExamplesProjectInput , existing_router : Arc < Router < Rule > > ) -> TestExamplesOutput {
6767 let test_example_router = test_examples_input. change_set . update_existing_router ( existing_router) ;
68- let mut results = TestExamplesOutput :: default ( ) ;
69-
70- for ( id, route) in test_example_router. routes ( ) {
71- let examples = & route. handler ( ) . examples ;
72-
73- if examples. is_none ( ) {
74- continue ;
75- }
76-
77- for example in examples. as_ref ( ) . unwrap ( ) . iter ( ) {
78- if example. unit_ids_applied . is_none ( ) {
79- continue ;
80- }
81-
82- let request = match Request :: from_example ( & test_example_router. config , example) {
83- Ok ( request) => request,
84- Err ( e) => {
85- results. add_errored_example ( route. handler ( ) , example. clone ( ) , e. to_string ( ) ) ;
86- continue ;
87- }
88- } ;
89- let mut unit_trace = UnitTrace :: default ( ) ;
90-
91- let routes = test_example_router. match_request ( & request) ;
92- let mut action = Action :: from_routes_rule ( routes, & request, Some ( & mut unit_trace) ) ;
93-
94- let action_status_code = action. get_status_code ( 0 , Some ( & mut unit_trace) ) ;
95- let ( final_status_code, backend_status_code) = if action_status_code != 0 {
96- ( action_status_code, action_status_code)
97- } else {
98- // We call the backend and get a response code
99- let backend_status_code = example. response_status_code . unwrap_or ( 200 ) ;
100- let final_status_code = action. get_status_code ( backend_status_code, Some ( & mut unit_trace) ) ;
101- ( final_status_code, backend_status_code)
102- } ;
10368
104- action. filter_headers ( Vec :: new ( ) , backend_status_code, false , Some ( & mut unit_trace) ) ;
105-
106- if let Some ( mut body_filter) = action. create_filter_body ( backend_status_code, & [ ] ) {
107- let body = "<!DOCTYPE html>
108- <html>
109- <head>
110- </head>
111- <body>
112- </body>
113- </html>" ;
114-
115- body_filter. filter ( body. into ( ) , Some ( & mut unit_trace) ) ;
116- body_filter. end ( Some ( & mut unit_trace) ) ;
117- }
118-
119- action. should_log_request ( true , final_status_code, Some ( & mut unit_trace) ) ;
120-
121- unit_trace. squash_with_target_unit_traces ( ) ;
122-
123- let unit_ids_not_applied_anymore = unit_trace. diff ( example. unit_ids_applied . clone ( ) . unwrap ( ) ) ;
124-
125- // If it should match but not unit are applied anymore
126- // If it should match but the rule is not applied
127- // If it should not matche but the rule is applied
128- if example. must_match && ( !unit_ids_not_applied_anymore. is_empty ( ) || !unit_trace. rule_ids_contains ( id. as_str ( ) ) )
129- || !example. must_match && unit_trace. rule_ids_contains ( id. as_str ( ) )
130- {
131- results. add_failed_example (
132- route. handler ( ) ,
133- example. clone ( ) ,
134- unit_trace. get_rule_ids_applied ( ) ,
135- unit_trace. get_unit_ids_applied ( ) ,
136- unit_ids_not_applied_anymore,
137- ) ;
138- }
139-
140- results. increment_example_count ( ) ;
141- }
142- }
143-
144- results
69+ Self :: create_result ( & test_example_router)
14570 }
14671
147- pub fn create_result ( test_examples_input : TestExamplesInput ) -> TestExamplesOutput {
72+ pub fn create_result_without_project ( test_examples_input : TestExamplesInput ) -> TestExamplesOutput {
14873 let mut router = Router :: < Rule > :: from_config ( test_examples_input. router_config . clone ( ) ) ;
14974
15075 for rule in test_examples_input. rules . iter ( ) {
15176 router. insert ( rule. clone ( ) ) ;
15277 }
15378
154- router. cache ( 10000 ) ;
79+ Self :: create_result ( & router)
80+ }
15581
82+ fn create_result ( router : & Router < Rule > ) -> TestExamplesOutput {
15683 let mut results = TestExamplesOutput :: default ( ) ;
15784
158- for rule in test_examples_input. rules . iter ( ) {
159- if rule. examples . is_none ( ) {
85+ for ( id, route) in router. routes ( ) {
86+ let examples = & route. handler ( ) . examples ;
87+
88+ if examples. is_none ( ) {
16089 continue ;
16190 }
16291
163- for example in rule . examples . as_ref ( ) . unwrap ( ) . iter ( ) {
92+ for example in examples. as_ref ( ) . unwrap ( ) . iter ( ) {
16493 if example. unit_ids_applied . is_none ( ) {
16594 continue ;
16695 }
16796
168- let request = match Request :: from_example ( & test_examples_input . router_config , example) {
97+ let request = match Request :: from_example ( & router . config , example) {
16998 Ok ( request) => request,
17099 Err ( e) => {
171- results. add_errored_example ( rule , example. clone ( ) , e. to_string ( ) ) ;
100+ results. add_errored_example ( route . handler ( ) , example. clone ( ) , e. to_string ( ) ) ;
172101 continue ;
173102 }
174103 } ;
@@ -211,11 +140,11 @@ impl TestExamplesOutput {
211140 // If it should match but not unit are applied anymore
212141 // If it should match but the rule is not applied
213142 // If it should not matche but the rule is applied
214- if example. must_match && ( !unit_ids_not_applied_anymore. is_empty ( ) || !unit_trace. rule_ids_contains ( rule . id . as_str ( ) ) )
215- || !example. must_match && unit_trace. rule_ids_contains ( rule . id . as_str ( ) )
143+ if example. must_match && ( !unit_ids_not_applied_anymore. is_empty ( ) || !unit_trace. rule_ids_contains ( id. as_str ( ) ) )
144+ || !example. must_match && unit_trace. rule_ids_contains ( id. as_str ( ) )
216145 {
217146 results. add_failed_example (
218- rule ,
147+ route . handler ( ) ,
219148 example. clone ( ) ,
220149 unit_trace. get_rule_ids_applied ( ) ,
221150 unit_trace. get_unit_ids_applied ( ) ,
0 commit comments