Skip to content

Commit

Permalink
chore: Add clippy and fix some lint warnings (#25)
Browse files Browse the repository at this point in the history
This adds a lint action for GHA. Also fixes some warnings turned up by
clippy, and disables dead code warnings for this crate.
  • Loading branch information
wedamija authored Jun 5, 2024
1 parent 31b6e9e commit 62a241c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ jobs:
run: cargo update
- name: Run Cargo Tests
run: cargo test
lint:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Rust Toolchain
run: rustup toolchain install stable --profile minimal --no-self-update
- name: Update cargo
run: cargo update
- name: Lint
run: cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings

20 changes: 10 additions & 10 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use reqwest::{Response, StatusCode};

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum CheckResult {
SUCCESS,
FAILURE(FailureReason),
MISSED,
Success,
Failure(FailureReason),
Missed,
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
Expand Down Expand Up @@ -34,10 +34,10 @@ pub async fn do_request(
/// Up is defined as returning a 2xx within a specific timeframe.
pub async fn check_url(client: &reqwest::Client, url: String) -> CheckResult {
match do_request(client, url).await {
Ok(_) => CheckResult::SUCCESS,
Ok(_) => CheckResult::Success,
Err(e) => {
if e.is_timeout() {
return CheckResult::FAILURE(FailureReason::Timeout);
return CheckResult::Failure(FailureReason::Timeout);
}
// TODO: More reasons
let mut inner = &e as &dyn Error;
Expand All @@ -48,13 +48,13 @@ pub async fn check_url(client: &reqwest::Client, url: String) -> CheckResult {
// Not sure if there's a better way
let inner_message = inner.to_string();
if inner_message.contains("dns error") {
return CheckResult::FAILURE(FailureReason::DnsError(
return CheckResult::Failure(FailureReason::DnsError(
inner.source().unwrap().to_string(),
));
}
}
// TODO: Should incorporate status code somehow
CheckResult::FAILURE(FailureReason::Error(format!("{:?}", e)))
CheckResult::Failure(FailureReason::Error(format!("{:?}", e)))
}
}
}
Expand Down Expand Up @@ -93,15 +93,15 @@ mod tests {

assert_eq!(
check_url(&client, server.url("/head")).await,
CheckResult::SUCCESS
CheckResult::Success
);
assert_eq!(
check_url(&client, server.url("/no-head")).await,
CheckResult::SUCCESS
CheckResult::Success
);
assert_eq!(
check_url(&client, server.url("/timeout")).await,
CheckResult::FAILURE(FailureReason::Timeout)
CheckResult::Failure(FailureReason::Timeout)
);
head_mock.assert();
head_disallowed_mock.assert();
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: We might want to remove this once more stable, but it's just noisy for now.
#![allow(dead_code)]
mod checker;
mod cli;
mod cliapp;
Expand Down

0 comments on commit 62a241c

Please sign in to comment.