diff --git a/src/configuration.rs b/src/configuration.rs index de84f6d..7f9771f 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -277,7 +277,7 @@ mod test { } assert!(res.is_ok()); - let filter_config = res.unwrap(); + let filter_config = res.expect("result is ok"); assert_eq!(filter_config.action_sets.len(), 1); let services = &filter_config.services; @@ -364,7 +364,7 @@ mod test { } assert!(res.is_ok()); - let filter_config = res.unwrap(); + let filter_config = res.expect("result is ok"); assert_eq!(filter_config.action_sets.len(), 0); } @@ -410,12 +410,15 @@ mod test { } assert!(res.is_ok()); - let filter_config = res.unwrap(); + let filter_config = res.expect("result is ok"); assert_eq!(filter_config.action_sets.len(), 1); let services = &filter_config.services; assert_eq!( - services.get("limitador").unwrap().timeout, + services + .get("limitador") + .expect("limitador service to be set") + .timeout, Timeout(Duration::from_millis(20)) ); @@ -510,7 +513,7 @@ mod test { } assert!(res.is_ok()); - let result = FilterConfig::try_from(res.unwrap()); + let result = FilterConfig::try_from(res.expect("result is ok")); let filter_config = result.expect("That didn't work"); let rlp_option = filter_config .index diff --git a/src/configuration/action_set_index.rs b/src/configuration/action_set_index.rs index e2153ce..068fd96 100644 --- a/src/configuration/action_set_index.rs +++ b/src/configuration/action_set_index.rs @@ -68,7 +68,7 @@ mod tests { let val = index.get_longest_match_action_sets("example.com"); assert!(val.is_some()); - assert_eq!(val.unwrap()[0].name, "rlp1"); + assert_eq!(val.expect("value must be some")[0].name, "rlp1"); } #[test] @@ -90,7 +90,7 @@ mod tests { let val = index.get_longest_match_action_sets("test.example.com"); assert!(val.is_some()); - assert_eq!(val.unwrap()[0].name, "rlp1"); + assert_eq!(val.expect("value must be some")[0].name, "rlp1"); } #[test] @@ -103,11 +103,11 @@ mod tests { let val = index.get_longest_match_action_sets("test.example.com"); assert!(val.is_some()); - assert_eq!(val.unwrap()[0].name, "rlp2"); + assert_eq!(val.expect("value must be some")[0].name, "rlp2"); let val = index.get_longest_match_action_sets("example.com"); assert!(val.is_some()); - assert_eq!(val.unwrap()[0].name, "rlp1"); + assert_eq!(val.expect("value must be some")[0].name, "rlp1"); } #[test] @@ -118,6 +118,6 @@ mod tests { let val = index.get_longest_match_action_sets("test.example.com"); assert!(val.is_some()); - assert_eq!(val.unwrap()[0].name, "rlp1"); + assert_eq!(val.expect("value must be some")[0].name, "rlp1"); } } diff --git a/src/data/cel.rs b/src/data/cel.rs index 2e6dc1b..c6b5e39 100644 --- a/src/data/cel.rs +++ b/src/data/cel.rs @@ -557,10 +557,14 @@ pub mod data { fn it_works() { let map = AttributeMap::new( [ - known_attribute_for(&"request.method".into()).unwrap(), - known_attribute_for(&"request.referer".into()).unwrap(), - known_attribute_for(&"source.address".into()).unwrap(), - known_attribute_for(&"destination.port".into()).unwrap(), + known_attribute_for(&"request.method".into()) + .expect("request.method known attribute exists"), + known_attribute_for(&"request.referer".into()) + .expect("request.referer known attribute exists"), + known_attribute_for(&"source.address".into()) + .expect("source.address known attribute exists"), + known_attribute_for(&"destination.port".into()) + .expect("destination.port known attribute exists"), ] .into(), ); @@ -572,10 +576,10 @@ pub mod data { assert!(map.data.contains_key("destination")); assert!(map.data.contains_key("request")); - match map.data.get("source").unwrap() { + match map.data.get("source").expect("source is some") { Token::Node(map) => { assert_eq!(map.len(), 1); - match map.get("address").unwrap() { + match map.get("address").expect("address is some") { Token::Node(_) => panic!("Not supposed to get here!"), Token::Value(v) => assert_eq!(v.path, "source.address".into()), } @@ -583,10 +587,10 @@ pub mod data { Token::Value(_) => panic!("Not supposed to get here!"), } - match map.data.get("destination").unwrap() { + match map.data.get("destination").expect("destination is some") { Token::Node(map) => { assert_eq!(map.len(), 1); - match map.get("port").unwrap() { + match map.get("port").expect("port is some") { Token::Node(_) => panic!("Not supposed to get here!"), Token::Value(v) => assert_eq!(v.path, "destination.port".into()), } @@ -594,16 +598,16 @@ pub mod data { Token::Value(_) => panic!("Not supposed to get here!"), } - match map.data.get("request").unwrap() { + match map.data.get("request").expect("request is some") { Token::Node(map) => { assert_eq!(map.len(), 2); assert!(map.get("method").is_some()); - match map.get("method").unwrap() { + match map.get("method").expect("method is some") { Token::Node(_) => panic!("Not supposed to get here!"), Token::Value(v) => assert_eq!(v.path, "request.method".into()), } assert!(map.get("referer").is_some()); - match map.get("referer").unwrap() { + match map.get("referer").expect("referer is some") { Token::Node(_) => panic!("Not supposed to get here!"), Token::Value(v) => assert_eq!(v.path, "request.referer".into()), } @@ -635,7 +639,7 @@ mod tests { let value = Expression::new( "auth.identity.anonymous && auth.identity != null && auth.identity.foo > 3", ) - .unwrap(); + .expect("This is valid CEL!"); assert_eq!(value.attributes.len(), 3); assert_eq!(value.attributes[0].path, "auth.identity".into()); } @@ -650,7 +654,7 @@ mod tests { "true".bytes().collect(), ))); let value = Expression::new("auth.identity.anonymous") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, true.into()); @@ -660,7 +664,7 @@ mod tests { "42".bytes().collect(), ))); let value = Expression::new("auth.identity.age") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, 42.into()); @@ -670,7 +674,7 @@ mod tests { "42.3".bytes().collect(), ))); let value = Expression::new("auth.identity.age") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, 42.3.into()); @@ -680,7 +684,7 @@ mod tests { "\"John\"".bytes().collect(), ))); let value = Expression::new("auth.identity.age") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, "John".into()); @@ -690,7 +694,7 @@ mod tests { "-42".bytes().collect(), ))); let value = Expression::new("auth.identity.name") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, (-42).into()); @@ -701,7 +705,7 @@ mod tests { "some random crap".bytes().collect(), ))); let value = Expression::new("auth.identity.age") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, "some random crap".into()); @@ -775,12 +779,14 @@ mod tests { 80_i64.to_le_bytes().into(), ))); let value = known_attribute_for(&"destination.port".into()) - .unwrap() + .expect("destination.port known attribute exists") .get(); assert_eq!(value, 80.into()); property::test::TEST_PROPERTY_VALUE .set(Some(("request.method".into(), "GET".bytes().collect()))); - let value = known_attribute_for(&"request.method".into()).unwrap().get(); + let value = known_attribute_for(&"request.method".into()) + .expect("request.method known attribute exists") + .get(); assert_eq!(value, "GET".into()); } @@ -802,7 +808,7 @@ mod tests { b"\xCA\xFE".to_vec(), ))); let value = Expression::new("getHostProperty(['foo', 'bar.baz'])") - .unwrap() + .expect("This is valid CEL!") .eval() .expect("This must evaluate!"); assert_eq!(value, Value::Bytes(Arc::new(b"\xCA\xFE".to_vec()))); diff --git a/src/lib.rs b/src/lib.rs index 75421e0..3590f4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,9 @@ mod tests { .push(header("test", "some value")); resp.response_headers_to_add .push(header("other", "header value")); - let buffer = resp.write_to_bytes().unwrap(); + let buffer = resp + .write_to_bytes() + .expect("must be able to write RateLimitResponse to bytes"); let expected: [u8; 45] = [ 8, 1, 26, 18, 10, 4, 116, 101, 115, 116, 18, 10, 115, 111, 109, 101, 32, 118, 97, 108, 117, 101, 26, 21, 10, 5, 111, 116, 104, 101, 114, 18, 12, 104, 101, 97, 100, 101, 114, diff --git a/src/operation_dispatcher.rs b/src/operation_dispatcher.rs index cc17143..3b7779c 100644 --- a/src/operation_dispatcher.rs +++ b/src/operation_dispatcher.rs @@ -463,34 +463,84 @@ mod tests { assert_eq!(operation_dispatcher.waiting_operations.len(), 0); let mut op = operation_dispatcher.next(); - assert_eq!(op.clone().unwrap().unwrap().get_result(), Ok(66)); assert_eq!( - *op.clone().unwrap().unwrap().get_service_type(), + op.clone() + .expect("ok result") + .expect("operation is some") + .get_result(), + Ok(66) + ); + assert_eq!( + *op.clone() + .expect("ok result") + .expect("operation is some") + .get_service_type(), ServiceType::RateLimit ); - assert_eq!(op.unwrap().unwrap().get_state(), State::Waiting); + assert_eq!( + op.expect("ok result") + .expect("operation is some") + .get_state(), + State::Waiting + ); assert_eq!(operation_dispatcher.waiting_operations.len(), 1); op = operation_dispatcher.next(); - assert_eq!(op.clone().unwrap().unwrap().get_result(), Ok(66)); - assert_eq!(op.unwrap().unwrap().get_state(), State::Done); + assert_eq!( + op.clone() + .expect("ok result") + .expect("operation is some") + .get_result(), + Ok(66) + ); + assert_eq!( + op.expect("ok result") + .expect("operation is some") + .get_state(), + State::Done + ); op = operation_dispatcher.next(); - assert_eq!(op.clone().unwrap().unwrap().get_result(), Ok(77)); assert_eq!( - *op.clone().unwrap().unwrap().get_service_type(), + op.clone() + .expect("ok result") + .expect("operation is some") + .get_result(), + Ok(77) + ); + assert_eq!( + *op.clone() + .expect("ok result") + .expect("operation is some") + .get_service_type(), ServiceType::Auth ); - assert_eq!(op.unwrap().unwrap().get_state(), State::Waiting); + assert_eq!( + op.expect("ok result") + .expect("operation is some") + .get_state(), + State::Waiting + ); assert_eq!(operation_dispatcher.waiting_operations.len(), 1); op = operation_dispatcher.next(); - assert_eq!(op.clone().unwrap().unwrap().get_result(), Ok(77)); - assert_eq!(op.unwrap().unwrap().get_state(), State::Done); + assert_eq!( + op.clone() + .expect("ok result") + .expect("operation is some") + .get_result(), + Ok(77) + ); + assert_eq!( + op.expect("ok result") + .expect("operation is some") + .get_state(), + State::Done + ); assert_eq!(operation_dispatcher.waiting_operations.len(), 1); op = operation_dispatcher.next(); - assert!(op.unwrap().is_none()); + assert!(op.expect("ok result").is_none()); assert!(operation_dispatcher.get_current_operation_state().is_none()); assert_eq!(operation_dispatcher.waiting_operations.len(), 0); } diff --git a/src/service/rate_limit.rs b/src/service/rate_limit.rs index d2a692f..b4dcf80 100644 --- a/src/service/rate_limit.rs +++ b/src/service/rate_limit.rs @@ -106,8 +106,22 @@ mod tests { assert_eq!(msg.hits_addend, 1); assert_eq!(msg.domain, "rlp1".to_string()); - assert_eq!(msg.descriptors.first().unwrap().entries[0].key, "key1"); - assert_eq!(msg.descriptors.first().unwrap().entries[0].value, "value1"); + assert_eq!( + msg.descriptors + .first() + .expect("must have a descriptor") + .entries[0] + .key, + "key1" + ); + assert_eq!( + msg.descriptors + .first() + .expect("must have a descriptor") + .entries[0] + .value, + "value1" + ); assert_eq!(msg.unknown_fields, UnknownFields::default()); assert_eq!(msg.cached_size, CachedSize::default()); }