Skip to content
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

Merged
merged 10 commits into from
Jun 5, 2024
Merged

Conversation

wedamija
Copy link
Member

@wedamija wedamija commented Jun 4, 2024

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.

src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated
}
}

return CheckResult::FAILURE(FailureReason::Error(format!("{:?}", e)));
Copy link
Member Author

@wedamija wedamija Jun 4, 2024

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 Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated
Comment on lines 72 to 113
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())));
}
}
Copy link
Member

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? ☠️

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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

@evanpurkhiser evanpurkhiser requested a review from a team June 4, 2024 17:10
src/checker.rs Outdated
Error(String),
}

pub async fn check_domain(domain: String) -> CheckResult {
Copy link

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.

src/checker.rs Outdated Show resolved Hide resolved
Copy link

@loewenheim loewenheim left a 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.

src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
src/checker.rs Outdated Show resolved Hide resolved
@@ -8,6 +8,8 @@ edition = "2021"
[dependencies]
anyhow = "1.0.66"
clap = { version = "4.4.6" }
httpmock = "0.7.0-rc.1"
Copy link
Member Author

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

src/checker.rs Outdated Show resolved Hide resolved
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.
@wedamija wedamija dismissed loewenheim’s stale review June 5, 2024 22:38

Feedback is addressed, we'll follow up with clippy afterwards

@wedamija wedamija merged commit 31b6e9e into main Jun 5, 2024
4 checks passed
@wedamija wedamija deleted the danf/check-domain branch June 5, 2024 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants