Skip to content

Commit

Permalink
chore: enable clippy for tests and fix lints (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 authored Jan 17, 2024
1 parent 51acc7c commit e637805
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
args: --all-features --all-targets

check-docs:
name: Check rustdoc
Expand Down
2 changes: 1 addition & 1 deletion benches/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub async fn ws_server(handle: tokio::runtime::Handle) -> (String, jsonrpc_ws_se
use jsonrpc_ws_server::jsonrpc_core::*;
use jsonrpc_ws_server::*;

const ID: AtomicU64 = AtomicU64::new(0);
static ID: AtomicU64 = AtomicU64::new(0);

let handle2 = handle.clone();

Expand Down
2 changes: 1 addition & 1 deletion client/ws-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async fn batch_request_with_failed_call_gives_proper_error() {
.unwrap()
.unwrap();
let err: Vec<_> = res.into_ok().unwrap_err().collect();
assert_eq!(err, vec![ErrorObject::from(ErrorCode::MethodNotFound), ErrorObject::borrowed(-32602, &"foo", None)]);
assert_eq!(err, vec![ErrorObject::from(ErrorCode::MethodNotFound), ErrorObject::borrowed(-32602, "foo", None)]);
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/jsonrpsee_server_low_level_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
MethodResponse::error(req.id, ErrorObject::borrowed(-32000, "RPC rate limit", None))
} else {
let rp = service.call(req).await;
*lock = *lock + 1;
*lock += 1;
rp
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
let handle = run_server();

let client = HttpClientBuilder::default().build("http://127.0.0.1:9944").unwrap();
while let Ok(_) = client.say_hello().await {
while client.say_hello().await.is_ok() {
i += 1;
}
tracing::info!("HTTP client made {i} successful calls before getting blacklisted");
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/rpc_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async fn run_server() -> anyhow::Result<SocketAddr> {
let global_cnt = Arc::new(AtomicUsize::new(0));

let rpc_middleware = RpcServiceBuilder::new()
.layer_fn(|service| Logger(service))
.layer_fn(Logger)
// This state is created per connection.
.layer_fn(|service| CallsPerConn { service, count: Default::default() })
// This state is shared by all connections.
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/rpc_middleware_modify_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn main() -> anyhow::Result<()> {
}

async fn run_server() -> anyhow::Result<SocketAddr> {
let rpc_middleware = RpcServiceBuilder::new().layer_fn(|service| ModifyRequestIf(service));
let rpc_middleware = RpcServiceBuilder::new().layer_fn(ModifyRequestIf);
let server = Server::builder().set_rpc_middleware(rpc_middleware).build("127.0.0.1:0").await?;
let mut module = RpcModule::new(());
module.register_method("say_hello", |_, _| "lo")?;
Expand Down
2 changes: 1 addition & 1 deletion server/src/middleware/http/host_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod tests {
}

fn unwrap_filter(list: &[&str]) -> WhitelistedHosts {
let l: Vec<_> = list.into_iter().map(|&a| a.try_into().unwrap()).collect();
let l: Vec<_> = list.iter().map(|&a| a.try_into().unwrap()).collect();
WhitelistedHosts::from(l)
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn stop_works() {
// First `unwrap` is timeout, second is `JoinHandle`'s one.

// After server was stopped, attempt to stop it again should result in an error.
assert!(matches!(server_handle.stop(), Err(_)));
assert!(server_handle.stop().is_err());
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion server/src/tests/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async fn batch_method_call_where_some_calls_fail() {
let addr = server().await;
let mut client = WebSocketTestClient::new(addr).with_default_timeout().await.unwrap().unwrap();

let batch = vec![
let batch = [
r#"{"jsonrpc":"2.0","method":"say_hello","id":1}"#,
r#"{"jsonrpc":"2.0","method":"call_fail","id":2}"#,
r#"{"jsonrpc":"2.0","method":"add","params":[34, 45],"id":3}"#,
Expand Down
13 changes: 6 additions & 7 deletions tests/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// DEALINGS IN THE SOFTWARE.

#![cfg(test)]
#![allow(clippy::blacklisted_name)]
#![allow(clippy::disallowed_names)]

mod helpers;

Expand Down Expand Up @@ -480,7 +480,7 @@ async fn ws_close_pending_subscription_when_server_terminated() {
c1.subscribe("subscribe_hello", rpc_params![], "unsubscribe_hello").await;

// no new request should be accepted.
assert!(matches!(sub2, Err(_)));
assert!(sub2.is_err());

// consume final message
for _ in 0..2 {
Expand Down Expand Up @@ -758,7 +758,7 @@ async fn ws_batch_works() {
})
.collect();
assert_eq!(ok_responses, vec!["hello"]);
assert_eq!(err_responses, vec![&ErrorObject::borrowed(UNKNOWN_ERROR_CODE, &"err", None)]);
assert_eq!(err_responses, vec![&ErrorObject::borrowed(UNKNOWN_ERROR_CODE, "err", None)]);
}

#[tokio::test]
Expand Down Expand Up @@ -798,7 +798,7 @@ async fn http_batch_works() {
})
.collect();
assert_eq!(ok_responses, vec!["hello"]);
assert_eq!(err_responses, vec![&ErrorObject::borrowed(UNKNOWN_ERROR_CODE, &"err", None)]);
assert_eq!(err_responses, vec![&ErrorObject::borrowed(UNKNOWN_ERROR_CODE, "err", None)]);
}

#[tokio::test]
Expand Down Expand Up @@ -942,7 +942,6 @@ async fn http_correct_content_type_required() {
init_logger();

let server_addr = server().await;

let http_client = Client::new();
let uri = format!("http://{}", server_addr);

Expand Down Expand Up @@ -1336,11 +1335,11 @@ async fn run_shutdown_test(transport: &str) {

match transport {
"ws" => {
let ws = Arc::new(WsClientBuilder::default().build(&format!("ws://{addr}")).await.unwrap());
let ws = Arc::new(WsClientBuilder::default().build(format!("ws://{addr}")).await.unwrap());
run_shutdown_test_inner(ws, handle, call_answered, call_ack).await
}
"http" => {
let http = Arc::new(HttpClientBuilder::default().build(&format!("http://{addr}")).unwrap());
let http = Arc::new(HttpClientBuilder::default().build(format!("http://{addr}")).unwrap());
run_shutdown_test_inner(http, handle, call_answered, call_ack).await
}
_ => unreachable!("Only `http` and `ws` supported"),
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ async fn subscribing_without_server() {
assert_eq!(&id, my_sub.subscription_id());
}

assert!(matches!(my_sub.next::<char>().await, None));
assert!(my_sub.next::<char>().await.is_none());
}

#[tokio::test]
Expand Down Expand Up @@ -298,7 +298,7 @@ async fn close_test_subscribing_without_server() {

// The first subscription was not closed using the unsubscribe method and
// it will be treated as the connection was closed.
assert!(matches!(my_sub.next::<String>().await, None));
assert!(my_sub.next::<String>().await.is_none());

// The second subscription still works
let (val, _) = my_sub2.next::<String>().await.unwrap().unwrap();
Expand All @@ -308,7 +308,7 @@ async fn close_test_subscribing_without_server() {
std::mem::ManuallyDrop::drop(&mut my_sub2);
}

assert!(matches!(my_sub.next::<String>().await, None));
assert!(my_sub.next::<String>().await.is_none());
}

#[tokio::test]
Expand Down Expand Up @@ -404,7 +404,7 @@ async fn rejected_subscription_without_server() {
let mut module = RpcModule::new(());
module
.register_subscription("my_sub", "my_sub", "my_unsub", |_, pending, _| async move {
let err = ErrorObject::borrowed(PARSE_ERROR_CODE, &"rejected", None);
let err = ErrorObject::borrowed(PARSE_ERROR_CODE, "rejected", None);
pending.reject(err.into_owned()).await;
Ok(())
})
Expand Down

0 comments on commit e637805

Please sign in to comment.