Skip to content

Commit

Permalink
Update expected logging in integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
  • Loading branch information
adam-cattermole committed Jan 16, 2025
1 parent 8a76515 commit bc55c1c
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 44 deletions.
53 changes: 46 additions & 7 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ fn it_auths() {
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some(data::source::port::P_45000))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -182,7 +186,7 @@ fn it_auths() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -205,8 +209,13 @@ fn it_auths() {
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_auth_grpc_response: received OkHttpResponse"),
Some("process_response(auth): store_metadata"),
)
.expect_log(
Some(LogLevel::Debug),
Some("process_response(auth): received OkHttpResponse"),
)
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Done"))
.execute_and_expect(ReturnType::None)
.unwrap();

Expand Down Expand Up @@ -347,6 +356,10 @@ fn it_denies() {
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some(data::source::port::P_45000))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -365,7 +378,7 @@ fn it_denies() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -388,8 +401,13 @@ fn it_denies() {
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_auth_grpc_response: received DeniedHttpResponse"),
Some("process_response(auth): store_metadata"),
)
.expect_log(
Some(LogLevel::Debug),
Some("process_response(auth): received DeniedHttpResponse"),
)
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Die"))
.expect_send_local_response(
Some(401),
None,
Expand Down Expand Up @@ -548,6 +566,10 @@ fn it_does_not_fold_auth_actions() {
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some(data::source::port::P_45000))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -566,7 +588,7 @@ fn it_does_not_fold_auth_actions() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -589,7 +611,11 @@ fn it_does_not_fold_auth_actions() {
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_auth_grpc_response: received OkHttpResponse"),
Some("process_response(auth): store_metadata"),
)
.expect_log(
Some(LogLevel::Debug),
Some("process_response(auth): received OkHttpResponse"),
)
.expect_get_header_map_pairs(Some(MapType::HttpRequestHeaders))
.returning(None)
Expand Down Expand Up @@ -653,6 +679,10 @@ fn it_does_not_fold_auth_actions() {
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some(data::source::port::P_45000))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
.expect_grpc_call(
Some("authorino-cluster"),
Some("envoy.service.auth.v3.Authorization"),
Expand All @@ -662,6 +692,10 @@ fn it_does_not_fold_auth_actions() {
Some(5000),
)
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::None)
.unwrap();

Expand All @@ -683,8 +717,13 @@ fn it_does_not_fold_auth_actions() {
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_auth_grpc_response: received OkHttpResponse"),
Some("process_response(auth): store_metadata"),
)
.expect_log(
Some(LogLevel::Debug),
Some("process_response(auth): received OkHttpResponse"),
)
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Done"))
.execute_and_expect(ReturnType::None)
.unwrap();

Expand Down
36 changes: 30 additions & 6 deletions tests/failuremode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ fn it_runs_next_action_on_failure_when_failuremode_is_allow() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -119,7 +123,7 @@ fn it_runs_next_action_on_failure_when_failuremode_is_allow() {
.returning(Ok(first_call_token_id))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -132,8 +136,10 @@ fn it_runs_next_action_on_failure_when_failuremode_is_allow() {
Some(LogLevel::Debug),
Some(format!("#2 on_grpc_call_response: received gRPC call response: token: {first_call_token_id}, status: {status_code}").as_str()),
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&[]))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
.expect_grpc_call(
Some("limitador-cluster"),
Some("envoy.service.ratelimit.v3.RateLimitService"),
Expand All @@ -143,6 +149,10 @@ fn it_runs_next_action_on_failure_when_failuremode_is_allow() {
Some(5000),
)
.returning(Ok(second_call_token_id))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::None)
.unwrap();

Expand All @@ -159,6 +169,14 @@ fn it_runs_next_action_on_failure_when_failuremode_is_allow() {
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_response(rl): received OK response"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: Done"),
)
.execute_and_expect(ReturnType::None)
.unwrap();

Expand Down Expand Up @@ -264,6 +282,10 @@ fn it_stops_on_failure_when_failuremode_is_deny() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -282,7 +304,7 @@ fn it_stops_on_failure_when_failuremode_is_deny() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -294,8 +316,10 @@ fn it_stops_on_failure_when_failuremode_is_deny() {
Some(LogLevel::Debug),
Some(format!("#2 on_grpc_call_response: received gRPC call response: token: 42, status: {status_code}").as_str()),
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&[]))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: Die"),
)
.expect_send_local_response(Some(500), None, None, None)
.execute_and_expect(ReturnType::None)
.unwrap();
Expand Down
62 changes: 47 additions & 15 deletions tests/failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ fn it_fails_on_first_action_grpc_call() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -104,13 +108,10 @@ fn it_fails_on_first_action_grpc_call() {
)
.returning(Err(TestStatus::ParseFailure))
.expect_log(
Some(LogLevel::Error),
Some("OperationError { status: ParseFailure, failure_mode: Deny }"),
)
.expect_log(
Some(LogLevel::Warn),
Some("OperationError Status: ParseFailure"),
Some(LogLevel::Debug),
Some("handle_operation: failed to send grpc request `ParseFailure`"),
)
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Die"))
.expect_send_local_response(
Some(500),
Some("Internal Server Error.\n"),
Expand Down Expand Up @@ -219,6 +220,10 @@ fn it_fails_on_second_action_grpc_call() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -240,7 +245,7 @@ fn it_fails_on_second_action_grpc_call() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -254,6 +259,14 @@ fn it_fails_on_second_action_grpc_call() {
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_response(rl): received OK response"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
.expect_grpc_call(
Some("does-not-exist"),
Some("envoy.service.ratelimit.v3.RateLimitService"),
Expand All @@ -267,9 +280,10 @@ fn it_fails_on_second_action_grpc_call() {
)
.returning(Err(TestStatus::ParseFailure))
.expect_log(
Some(LogLevel::Error),
Some("OperationError { status: ParseFailure, failure_mode: Deny }"),
Some(LogLevel::Debug),
Some("handle_operation: failed to send grpc request `ParseFailure`"),
)
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Die"))
.expect_send_local_response(
Some(500),
Some("Internal Server Error.\n"),
Expand Down Expand Up @@ -358,6 +372,10 @@ fn it_fails_on_first_action_grpc_response() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -379,7 +397,7 @@ fn it_fails_on_first_action_grpc_response() {
.returning(Ok(42))
.expect_log(
Some(LogLevel::Debug),
Some("#2 initiated gRPC call (id# 42)"),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -391,8 +409,7 @@ fn it_fails_on_first_action_grpc_response() {
Some(LogLevel::Debug),
Some("#2 on_grpc_call_response: received gRPC call response: token: 42, status: 14"),
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&[]))
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Die"))
.expect_send_local_response(
Some(500),
Some("Internal Server Error.\n"),
Expand Down Expand Up @@ -500,6 +517,10 @@ fn it_fails_on_second_action_grpc_response() {
Some(LogLevel::Debug),
Some("#2 action_set selected some-name"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -521,7 +542,7 @@ fn it_fails_on_second_action_grpc_response() {
.returning(Ok(first_call_token_id))
.expect_log(
Some(LogLevel::Debug),
Some(format!("#2 initiated gRPC call (id# {first_call_token_id})").as_str()),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::Action(Action::Pause))
.unwrap();
Expand All @@ -540,6 +561,14 @@ fn it_fails_on_second_action_grpc_response() {
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&grpc_response))
.expect_log(
Some(LogLevel::Debug),
Some("process_response(rl): received OK response"),
)
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: SendGrpcRequest"),
)
.expect_grpc_call(
Some("unreachable-cluster"),
Some("envoy.service.ratelimit.v3.RateLimitService"),
Expand All @@ -552,6 +581,10 @@ fn it_fails_on_second_action_grpc_response() {
Some(5000),
)
.returning(Ok(second_call_token_id))
.expect_log(
Some(LogLevel::Debug),
Some("handle_operation: AwaitGrpcResponse"),
)
.execute_and_expect(ReturnType::None)
.unwrap();

Expand All @@ -564,8 +597,7 @@ fn it_fails_on_second_action_grpc_response() {
"#2 on_grpc_call_response: received gRPC call response: token: {second_call_token_id}, status: {status_code}"
).as_str()),
)
.expect_get_buffer_bytes(Some(BufferType::GrpcReceiveBuffer))
.returning(Some(&[]))
.expect_log(Some(LogLevel::Debug), Some("handle_operation: Die"))
.expect_send_local_response(
Some(500),
Some("Internal Server Error.\n"),
Expand Down
Loading

0 comments on commit bc55c1c

Please sign in to comment.