-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c880805
commit c860236
Showing
10 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ cli = 10000 | |
[health-check.database] | ||
|
||
[health-check.sidekiq] | ||
|
||
[health-check.smtp] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ cli = 10000 | |
|
||
[health-check.sidekiq] | ||
|
||
[health-check.smtp] | ||
|
||
[service] | ||
default-enable = true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[cfg(feature = "email-smtp")] | ||
pub mod smtp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::api::core::health::smtp_health; | ||
use crate::app::context::AppContext; | ||
use crate::error::RoadsterResult; | ||
use crate::health_check::{CheckResponse, HealthCheck}; | ||
use async_trait::async_trait; | ||
use tracing::instrument; | ||
|
||
pub struct SmtpHealthCheck { | ||
pub(crate) context: AppContext, | ||
} | ||
|
||
#[async_trait] | ||
impl HealthCheck for SmtpHealthCheck { | ||
fn name(&self) -> String { | ||
"smtp".to_string() | ||
} | ||
|
||
fn enabled(&self) -> bool { | ||
enabled(&self.context) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
async fn check(&self) -> RoadsterResult<CheckResponse> { | ||
Ok(smtp_health(&self.context, None).await) | ||
} | ||
} | ||
|
||
fn enabled(context: &AppContext) -> bool { | ||
context.config().health_check.smtp.common.enabled(context) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::config::AppConfig; | ||
use rstest::rstest; | ||
|
||
#[rstest] | ||
#[case(false, Some(true), true)] | ||
#[case(false, Some(false), false)] | ||
#[cfg_attr(coverage_nightly, coverage(off))] | ||
fn enabled( | ||
#[case] default_enable: bool, | ||
#[case] enable: Option<bool>, | ||
#[case] expected_enabled: bool, | ||
) { | ||
// Arrange | ||
let mut config = AppConfig::test(None).unwrap(); | ||
config.health_check.default_enable = default_enable; | ||
config.health_check.smtp.common.enable = enable; | ||
|
||
let context = AppContext::test(Some(config), None, None).unwrap(); | ||
|
||
// Act/Assert | ||
assert_eq!(super::enabled(&context), expected_enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ expression: health_checks | |
'db', | ||
'sidekiq-enqueue', | ||
'sidekiq-fetch', | ||
'smtp', | ||
] |