-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add function to perform domain checks #22
Conversation
src/checker.rs
Outdated
} | ||
} | ||
|
||
return CheckResult::FAILURE(FailureReason::Error(format!("{:?}", e))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably failure should include the status code too? (If present)
src/checker.rs
Outdated
mod tests { | ||
use super::{check_domain, CheckResult, FailureReason}; | ||
|
||
#[tokio::test] | ||
async fn test_add() { | ||
assert_eq!( | ||
check_domain("https://google.com".to_string()).await, | ||
CheckResult::SUCCESS | ||
); | ||
assert_eq!( | ||
check_domain("https://sentry.io".to_string()).await, | ||
CheckResult::SUCCESS | ||
); | ||
assert_eq!(check_domain("https://hjkhjkljkh.io".to_string()).await, CheckResult::FAILURE(FailureReason::DnsError("failed to lookup address information: nodename nor servname provided, or not known".to_string()))); | ||
assert_eq!(check_domain("https://santry.io".to_string()).await, CheckResult::FAILURE(FailureReason::DnsError("failed to lookup address information: nodename nor servname provided, or not known".to_string()))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires internet to run right? ☠️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm going to put mocks here later
src/checker.rs
Outdated
Error(String), | ||
} | ||
|
||
pub async fn check_domain(domain: String) -> CheckResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're using URLs without trailing /
, so you get 301 redirects, which Reqwest handles automatically, but it's kinda unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I would recommend running clippy
and setting it up as part of your CI. It's really helpful. Locally you can run it with cargo clippy
.
@@ -8,6 +8,8 @@ edition = "2021" | |||
[dependencies] | |||
anyhow = "1.0.66" | |||
clap = { version = "4.4.6" } | |||
httpmock = "0.7.0-rc.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose this over mockito since it also has the ability to simulate a delay/timeout
Add initial function to perform domain checks. We need better testing around this and probably also need return more useful failure reasons. I'll follow up later with a pr that adds mocking for the domains so we can test all the cases.
ae053d3
to
68c0d3b
Compare
Feedback is addressed, we'll follow up with clippy
afterwards
Add initial function to perform domain checks. We need better testing around this and probably also need return more useful failure reasons.
I'll follow up later with a pr that adds mocking for the domains so we can test all the cases.