From ec9079f483a174bead40c38624af8a505458cd83 Mon Sep 17 00:00:00 2001 From: Folke Behrens Date: Wed, 16 Apr 2025 20:05:21 +0000 Subject: [PATCH] Allow unwrap() in tests when clippy::unwrap_used is denied (#11616) ## Problem The proxy denies using `unwrap()`s in regular code, but we want to use it in test code and so have to allow it for each test block. ## Summary of changes Set `allow-unwrap-in-tests = true` in clippy.toml and remove all exceptions. --- clippy.toml | 2 ++ proxy/src/auth/backend/jwt.rs | 1 - proxy/src/auth/credentials.rs | 1 - proxy/src/cache/endpoints.rs | 1 - proxy/src/cache/project_info.rs | 1 - proxy/src/context/parquet.rs | 1 - proxy/src/intern.rs | 1 - proxy/src/logging.rs | 1 - proxy/src/protocol2.rs | 1 - proxy/src/proxy/copy_bidirectional.rs | 1 - proxy/src/proxy/tests/mod.rs | 2 +- proxy/src/rate_limiter/leaky_bucket.rs | 2 +- proxy/src/rate_limiter/limit_algorithm/aimd.rs | 1 - proxy/src/rate_limiter/limiter.rs | 1 - proxy/src/sasl/messages.rs | 1 - proxy/src/scram/messages.rs | 1 - proxy/src/scram/mod.rs | 1 - proxy/src/scram/secret.rs | 1 - proxy/src/serverless/conn_pool.rs | 1 - proxy/src/serverless/json.rs | 1 - proxy/src/serverless/local_conn_pool.rs | 1 - proxy/src/serverless/sql_over_http.rs | 1 - proxy/src/serverless/websocket.rs | 1 - proxy/src/url.rs | 1 - proxy/src/usage_metrics.rs | 1 - 25 files changed, 4 insertions(+), 24 deletions(-) diff --git a/clippy.toml b/clippy.toml index 4c0c04f9a1..408232488c 100644 --- a/clippy.toml +++ b/clippy.toml @@ -12,3 +12,5 @@ disallowed-macros = [ # cannot disallow this, because clippy finds used from tokio macros #"tokio::pin", ] + +allow-unwrap-in-tests = true diff --git a/proxy/src/auth/backend/jwt.rs b/proxy/src/auth/backend/jwt.rs index 942f1e13d1..44a6a42665 100644 --- a/proxy/src/auth/backend/jwt.rs +++ b/proxy/src/auth/backend/jwt.rs @@ -776,7 +776,6 @@ impl From<&jose_jwk::Key> for KeyType { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::future::IntoFuture; use std::net::SocketAddr; diff --git a/proxy/src/auth/credentials.rs b/proxy/src/auth/credentials.rs index c1b7718e4f..c55af325e3 100644 --- a/proxy/src/auth/credentials.rs +++ b/proxy/src/auth/credentials.rs @@ -253,7 +253,6 @@ fn project_name_valid(name: &str) -> bool { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use ComputeUserInfoParseError::*; use serde_json::json; diff --git a/proxy/src/cache/endpoints.rs b/proxy/src/cache/endpoints.rs index 8ec1a4648b..3c88e07484 100644 --- a/proxy/src/cache/endpoints.rs +++ b/proxy/src/cache/endpoints.rs @@ -259,7 +259,6 @@ impl EndpointsCache { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/cache/project_info.rs b/proxy/src/cache/project_info.rs index e153e9f61f..60678b034d 100644 --- a/proxy/src/cache/project_info.rs +++ b/proxy/src/cache/project_info.rs @@ -585,7 +585,6 @@ impl Cache for ProjectInfoCacheImpl { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; use crate::scram::ServerSecret; diff --git a/proxy/src/context/parquet.rs b/proxy/src/context/parquet.rs index bfab5f34f9..f6250bcd17 100644 --- a/proxy/src/context/parquet.rs +++ b/proxy/src/context/parquet.rs @@ -416,7 +416,6 @@ async fn upload_parquet( } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::net::Ipv4Addr; use std::num::NonZeroUsize; diff --git a/proxy/src/intern.rs b/proxy/src/intern.rs index 0d1382679c..d7e39ebaf4 100644 --- a/proxy/src/intern.rs +++ b/proxy/src/intern.rs @@ -227,7 +227,6 @@ impl From for AccountIdInt { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::sync::OnceLock; diff --git a/proxy/src/logging.rs b/proxy/src/logging.rs index 454fe81357..b83b03bc4f 100644 --- a/proxy/src/logging.rs +++ b/proxy/src/logging.rs @@ -1032,7 +1032,6 @@ impl serde::ser::Serialize for ExtractedSpanFields<'_, F> { } #[cfg(test)] -#[allow(clippy::unwrap_used)] mod tests { use std::marker::PhantomData; use std::sync::{Arc, Mutex, MutexGuard}; diff --git a/proxy/src/protocol2.rs b/proxy/src/protocol2.rs index b0603da379..ecd9882f53 100644 --- a/proxy/src/protocol2.rs +++ b/proxy/src/protocol2.rs @@ -400,7 +400,6 @@ impl NetworkEndianIpv6 { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use tokio::io::AsyncReadExt; diff --git a/proxy/src/proxy/copy_bidirectional.rs b/proxy/src/proxy/copy_bidirectional.rs index 6f8b972348..97f8d7c6af 100644 --- a/proxy/src/proxy/copy_bidirectional.rs +++ b/proxy/src/proxy/copy_bidirectional.rs @@ -262,7 +262,6 @@ impl CopyBuffer { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use tokio::io::AsyncWriteExt; diff --git a/proxy/src/proxy/tests/mod.rs b/proxy/src/proxy/tests/mod.rs index 2268e60d25..9a6864c33e 100644 --- a/proxy/src/proxy/tests/mod.rs +++ b/proxy/src/proxy/tests/mod.rs @@ -1,5 +1,5 @@ //! A group of high-level tests for connection establishing logic and auth. -#![allow(clippy::unimplemented, clippy::unwrap_used)] +#![allow(clippy::unimplemented)] mod mitm; diff --git a/proxy/src/rate_limiter/leaky_bucket.rs b/proxy/src/rate_limiter/leaky_bucket.rs index b3853d48e4..4f27c6faef 100644 --- a/proxy/src/rate_limiter/leaky_bucket.rs +++ b/proxy/src/rate_limiter/leaky_bucket.rs @@ -83,7 +83,7 @@ impl From for utils::leaky_bucket::LeakyBucketConfig { } #[cfg(test)] -#[allow(clippy::float_cmp, clippy::unwrap_used)] +#[allow(clippy::float_cmp)] mod tests { use std::time::Duration; diff --git a/proxy/src/rate_limiter/limit_algorithm/aimd.rs b/proxy/src/rate_limiter/limit_algorithm/aimd.rs index 04e136b6d5..3000cc4c2a 100644 --- a/proxy/src/rate_limiter/limit_algorithm/aimd.rs +++ b/proxy/src/rate_limiter/limit_algorithm/aimd.rs @@ -63,7 +63,6 @@ impl LimitAlgorithm for Aimd { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::time::Duration; diff --git a/proxy/src/rate_limiter/limiter.rs b/proxy/src/rate_limiter/limiter.rs index 71e2a92da6..21eaa6739b 100644 --- a/proxy/src/rate_limiter/limiter.rs +++ b/proxy/src/rate_limiter/limiter.rs @@ -259,7 +259,6 @@ impl BucketRateLimiter { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::hash::BuildHasherDefault; use std::time::Duration; diff --git a/proxy/src/sasl/messages.rs b/proxy/src/sasl/messages.rs index 4922ece615..7f2f3a761c 100644 --- a/proxy/src/sasl/messages.rs +++ b/proxy/src/sasl/messages.rs @@ -51,7 +51,6 @@ impl<'a> ServerMessage<&'a str> { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/scram/messages.rs b/proxy/src/scram/messages.rs index 7b0b861ce9..e071417dab 100644 --- a/proxy/src/scram/messages.rs +++ b/proxy/src/scram/messages.rs @@ -185,7 +185,6 @@ impl fmt::Debug for OwnedServerFirstMessage { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/scram/mod.rs b/proxy/src/scram/mod.rs index 24f991d4d9..4f764c6087 100644 --- a/proxy/src/scram/mod.rs +++ b/proxy/src/scram/mod.rs @@ -57,7 +57,6 @@ fn sha256<'a>(parts: impl IntoIterator) -> [u8; 32] { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::threadpool::ThreadPool; use super::{Exchange, ServerSecret}; diff --git a/proxy/src/scram/secret.rs b/proxy/src/scram/secret.rs index eb21b26ab4..8c6a08d432 100644 --- a/proxy/src/scram/secret.rs +++ b/proxy/src/scram/secret.rs @@ -72,7 +72,6 @@ impl ServerSecret { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/serverless/conn_pool.rs b/proxy/src/serverless/conn_pool.rs index 409056a6a9..87176ff7d6 100644 --- a/proxy/src/serverless/conn_pool.rs +++ b/proxy/src/serverless/conn_pool.rs @@ -189,7 +189,6 @@ impl ClientDataRemote { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::sync::atomic::AtomicBool; diff --git a/proxy/src/serverless/json.rs b/proxy/src/serverless/json.rs index 7235fb6079..1afc10359f 100644 --- a/proxy/src/serverless/json.rs +++ b/proxy/src/serverless/json.rs @@ -256,7 +256,6 @@ fn pg_array_parse_inner( } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use serde_json::json; diff --git a/proxy/src/serverless/local_conn_pool.rs b/proxy/src/serverless/local_conn_pool.rs index 3282c0ebde..1d9b35f41d 100644 --- a/proxy/src/serverless/local_conn_pool.rs +++ b/proxy/src/serverless/local_conn_pool.rs @@ -367,7 +367,6 @@ fn sign_jwt(sk: &SigningKey, payload: &[u8]) -> String { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use ed25519_dalek::SigningKey; use typed_json::json; diff --git a/proxy/src/serverless/sql_over_http.rs b/proxy/src/serverless/sql_over_http.rs index 972bf58d91..7fb39553f9 100644 --- a/proxy/src/serverless/sql_over_http.rs +++ b/proxy/src/serverless/sql_over_http.rs @@ -1209,7 +1209,6 @@ impl Discard<'_> { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/serverless/websocket.rs b/proxy/src/serverless/websocket.rs index 7fc48105c5..8648a94869 100644 --- a/proxy/src/serverless/websocket.rs +++ b/proxy/src/serverless/websocket.rs @@ -177,7 +177,6 @@ pub(crate) async fn serve_websocket( } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::pin::pin; diff --git a/proxy/src/url.rs b/proxy/src/url.rs index d73a84057a..270cd7c24d 100644 --- a/proxy/src/url.rs +++ b/proxy/src/url.rs @@ -50,7 +50,6 @@ impl std::fmt::Display for ApiUrl { } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use super::*; diff --git a/proxy/src/usage_metrics.rs b/proxy/src/usage_metrics.rs index 2b27dc5c76..115b958c54 100644 --- a/proxy/src/usage_metrics.rs +++ b/proxy/src/usage_metrics.rs @@ -497,7 +497,6 @@ async fn upload_backup_events( } #[cfg(test)] -#[expect(clippy::unwrap_used)] mod tests { use std::fs; use std::io::BufReader;