Skip to content

Commit

Permalink
Add tests for the Middleware::priority methods for each middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed May 15, 2024
1 parent 63d4dc5 commit b57d022
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/service/http/middleware/catch_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,30 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, 0)]
#[case(Some(1234), 1234)]
fn priority(#[case] override_priority: Option<i32>, #[case] expected_priority: i32) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.catch_panic
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = CatchPanicMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
58 changes: 58 additions & 0 deletions src/service/http/middleware/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ mod tests {
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, 0)]
#[case(Some(1234), 1234)]
fn response_compression_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.response_compression
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = ResponseCompressionMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}

#[rstest]
#[case(false, Some(true), true)]
#[case(false, Some(false), false)]
Expand Down Expand Up @@ -153,4 +182,33 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, -9960)]
#[case(Some(1234), 1234)]
fn request_decompression_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.request_decompression
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = RequestDecompressionMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
58 changes: 58 additions & 0 deletions src/service/http/middleware/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,35 @@ mod tests {
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, -9990)]
#[case(Some(1234), 1234)]
fn set_request_id_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.set_request_id
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = SetRequestIdMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}

#[rstest]
#[case(false, Some(true), true)]
#[case(false, Some(false), false)]
Expand Down Expand Up @@ -202,4 +231,33 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, 9990)]
#[case(Some(1234), 1234)]
fn propagate_request_id_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.propagate_request_id
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = PropagateRequestIdMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
58 changes: 58 additions & 0 deletions src/service/http/middleware/sensitive_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,35 @@ mod tests {
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, -10000)]
#[case(Some(1234), 1234)]
fn sensitive_request_headers_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.sensitive_request_headers
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = SensitiveRequestHeadersMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}

#[rstest]
#[case(false, Some(true), true)]
#[case(false, Some(false), false)]
Expand Down Expand Up @@ -213,4 +242,33 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, 10000)]
#[case(Some(1234), 1234)]
fn sensitive_response_headers_priority(
#[case] override_priority: Option<i32>,
#[case] expected_priority: i32,
) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.sensitive_response_headers
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = SensitiveResponseHeadersMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
26 changes: 26 additions & 0 deletions src/service/http/middleware/size_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,30 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, -9970)]
#[case(Some(1234), 1234)]
fn size_limit_priority(#[case] override_priority: Option<i32>, #[case] expected_priority: i32) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.size_limit
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = RequestBodyLimitMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
26 changes: 26 additions & 0 deletions src/service/http/middleware/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,30 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, 0)]
#[case(Some(1234), 1234)]
fn timeout_priority(#[case] override_priority: Option<i32>, #[case] expected_priority: i32) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.timeout
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = TimeoutMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}
26 changes: 26 additions & 0 deletions src/service/http/middleware/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,30 @@ mod tests {
// Act/Assert
assert_eq!(middleware.enabled(&context), expected_enabled);
}

#[rstest]
#[case(None, -9980)]
#[case(Some(1234), 1234)]
fn tracing_priority(#[case] override_priority: Option<i32>, #[case] expected_priority: i32) {
// Arrange
let mut config = AppConfig::empty(None).unwrap();
if let Some(priority) = override_priority {
config
.service
.http
.custom
.middleware
.tracing
.common
.priority = priority;
}

let mut context = MockAppContext::<()>::default();
context.expect_config().return_const(config);

let middleware = TracingMiddleware;

// Act/Assert
assert_eq!(middleware.priority(&context), expected_priority);
}
}

0 comments on commit b57d022

Please sign in to comment.