1
1
use crate :: configuration:: { ActionSet , Service } ;
2
- use crate :: data:: { Predicate , PredicateVec } ;
2
+ use crate :: data:: { Predicate , PredicateResult , PredicateVec } ;
3
3
use crate :: runtime_action:: RuntimeAction ;
4
4
use crate :: service:: { GrpcErrResponse , HeaderKind , IndexedGrpcRequest } ;
5
5
use std:: collections:: HashMap ;
@@ -56,9 +56,8 @@ impl RuntimeActionSet {
56
56
folded_actions
57
57
}
58
58
59
- pub fn conditions_apply ( & self ) -> bool {
60
- //todo(adam-cattermole): do not expect
61
- self . route_rule_predicates . apply ( ) . expect ( "REMOVE" )
59
+ pub fn conditions_apply ( & self ) -> PredicateResult {
60
+ self . route_rule_predicates . apply ( )
62
61
}
63
62
64
63
pub fn find_first_grpc_request ( & self ) -> Option < IndexedGrpcRequest > {
@@ -105,7 +104,8 @@ mod test {
105
104
let runtime_action_set = RuntimeActionSet :: new ( & action_set, & HashMap :: default ( ) )
106
105
. expect ( "should not happen from an empty set of actions" ) ;
107
106
108
- assert ! ( runtime_action_set. conditions_apply( ) )
107
+ assert ! ( runtime_action_set. conditions_apply( ) . is_ok( ) ) ;
108
+ assert ! ( runtime_action_set. conditions_apply( ) . unwrap( ) ) ;
109
109
}
110
110
111
111
#[ test]
@@ -122,7 +122,8 @@ mod test {
122
122
let runtime_action_set = RuntimeActionSet :: new ( & action_set, & HashMap :: default ( ) )
123
123
. expect ( "should not happen from an empty set of actions" ) ;
124
124
125
- assert ! ( runtime_action_set. conditions_apply( ) )
125
+ assert ! ( runtime_action_set. conditions_apply( ) . is_ok( ) ) ;
126
+ assert ! ( runtime_action_set. conditions_apply( ) . unwrap( ) ) ;
126
127
}
127
128
128
129
#[ test]
@@ -139,12 +140,12 @@ mod test {
139
140
let runtime_action_set = RuntimeActionSet :: new ( & action_set, & HashMap :: default ( ) )
140
141
. expect ( "should not happen from an empty set of actions" ) ;
141
142
142
- assert ! ( !runtime_action_set. conditions_apply( ) )
143
+ assert ! ( runtime_action_set. conditions_apply( ) . is_ok( ) ) ;
144
+ assert ! ( !runtime_action_set. conditions_apply( ) . unwrap( ) ) ;
143
145
}
144
146
145
147
#[ test]
146
- #[ should_panic]
147
- fn when_a_cel_expression_does_not_evaluate_to_bool_panics ( ) {
148
+ fn when_a_cel_expression_does_not_evaluate_to_bool_returns_error ( ) {
148
149
let action_set = ActionSet :: new (
149
150
"some_name" . to_owned ( ) ,
150
151
RouteRuleConditions {
@@ -156,7 +157,7 @@ mod test {
156
157
157
158
let runtime_action_set = RuntimeActionSet :: new ( & action_set, & HashMap :: default ( ) )
158
159
. expect ( "should not happen from an empty set of actions" ) ;
159
- runtime_action_set. conditions_apply ( ) ;
160
+ assert ! ( runtime_action_set. conditions_apply( ) . is_err ( ) ) ;
160
161
}
161
162
162
163
fn build_rl_service ( ) -> Service {
0 commit comments