Skip to content

Commit f707444

Browse files
committed
Tests cleanup; cargo clippy fixes, minor doc updates
1 parent e0a77fc commit f707444

16 files changed

+243
-156
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ hmac = { version = "0.12.1", optional = true }
4141
hyper = { version = "1.6.0", features = ["full"] }
4242
lazy_static = "1.5.0"
4343
log = "0.4.27"
44-
md5 = "0.7.0"
44+
md5 = "0.8.0"
4545
multimap = "0.10.1"
4646
percent-encoding = "2.3.1"
47+
url = "2.5.4"
4748
rand = { version = "0.8.5", features = ["small_rng"] }
4849
regex = "1.11.1"
4950
ring = { version = "0.17.14", optional = true, default-features = false, features = ["alloc"] }

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ chrono = "0.4.41"
1414
reqwest = "0.12.20"
1515
http = "1.3.1"
1616
futures = "0.3.31"
17+
uuid = { version = "1.17.0", features = ["v4"] }
1718

1819
[lib]
1920
name = "minio_common"

common/src/utils.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515

1616
use http::{Response as HttpResponse, StatusCode};
1717
use minio::s3::error::Error;
18-
use rand::distributions::{Alphanumeric, DistString};
18+
use rand::distributions::Standard;
19+
use rand::{Rng, thread_rng};
20+
use uuid::Uuid;
1921

2022
pub fn rand_bucket_name() -> String {
21-
Alphanumeric
22-
.sample_string(&mut rand::thread_rng(), 8)
23-
.to_lowercase()
23+
format!("test-bucket-{}", Uuid::new_v4())
2424
}
2525

2626
pub fn rand_object_name() -> String {
27-
Alphanumeric.sample_string(&mut rand::thread_rng(), 20)
27+
format!("test-object-{}", Uuid::new_v4())
28+
}
29+
30+
pub fn rand_object_name_utf8(len: usize) -> String {
31+
let rng = thread_rng();
32+
rng.sample_iter::<char, _>(Standard)
33+
.filter(|c| !c.is_control())
34+
.take(len)
35+
.collect()
2836
}
2937

3038
pub async fn get_bytes_from_response(v: Result<reqwest::Response, Error>) -> bytes::Bytes {

src/s3/builders/delete_objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl DeleteObjects {
209209
}
210210

211211
/// Enable verbose mode (defaults to false). If enabled, the response will
212-
/// include the keys of objects that were successfully deleted. Otherwise
212+
/// include the keys of objects that were successfully deleted. Otherwise,
213213
/// only objects that encountered an error are returned.
214214
pub fn verbose_mode(mut self, verbose_mode: bool) -> Self {
215215
self.verbose_mode = verbose_mode;

src/s3/client/delete_bucket.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ impl Client {
6161
let mut stream = self.list_objects(&bucket).to_stream().await;
6262

6363
while let Some(items) = stream.next().await {
64+
let object_names = items?.contents.into_iter().map(ObjectToDelete::from);
6465
let mut resp = self
65-
.delete_objects_streaming(
66-
&bucket,
67-
items?.contents.into_iter().map(ObjectToDelete::from),
68-
)
66+
.delete_objects_streaming(&bucket, object_names)
6967
.to_stream()
7068
.await;
7169
while let Some(item) = resp.next().await {

src/s3/client/delete_objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Client {
6666

6767
/// Creates a [`DeleteObjectsStreaming`] request builder to delete a stream of objects from an S3 bucket.
6868
///
69-
/// to execute the request, call [`DeleteObjectsStreaming::to_stream()`](crate::s3::types::S3Api::send),
69+
/// To execute the request, call [`DeleteObjectsStreaming::to_stream()`](crate::s3::types::S3Api::send),
7070
/// which returns a [`Result`] containing a [`DeleteObjectsResponse`](crate::s3::response::DeleteObjectsResponse).
7171
pub fn delete_objects_streaming<S: Into<String>, D: Into<ObjectsStream>>(
7272
&self,

src/s3/lifecycle_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,5 @@ impl LifecycleRule {
480480
fn parse_iso8601(date_str: &str) -> Result<chrono::DateTime<chrono::Utc>, Error> {
481481
chrono::DateTime::parse_from_rfc3339(date_str)
482482
.map(|dt| dt.with_timezone(&chrono::Utc))
483-
.map_err(|_| Error::XmlError(format!("Invalid date format: {}", date_str)))
483+
.map_err(|_| Error::XmlError(format!("Invalid date format: {date_str}")))
484484
}

src/s3/response/get_bucket_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl GetBucketPolicyResponse {
4848
/// for accessing the bucket and its contents.
4949
pub fn config(&self) -> Result<&str, Error> {
5050
std::str::from_utf8(&self.body).map_err(|e| {
51-
Error::Utf8Error(format!("Failed to parse bucket policy as UTF-8: {}", e).into())
51+
Error::Utf8Error(format!("Failed to parse bucket policy as UTF-8: {e}").into())
5252
})
5353
}
5454
}

src/s3/response/get_object_prompt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl GetObjectPromptResponse {
4040
/// This method retrieves the content of the object as a UTF-8 encoded string.
4141
pub fn prompt_response(&self) -> Result<&str, Error> {
4242
std::str::from_utf8(&self.body).map_err(|e| {
43-
Error::Utf8Error(format!("Failed to parse prompt_response as UTF-8: {}", e).into())
43+
Error::Utf8Error(format!("Failed to parse prompt_response as UTF-8: {e}").into())
4444
})
4545
}
4646
}

src/s3/response/list_objects.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
//! Response types for ListObjects APIs
14-
1513
use crate::impl_has_s3fields;
14+
use crate::s3::error::Error;
1615
use crate::s3::response::a_response_traits::HasS3Fields;
17-
use crate::s3::{
18-
error::Error,
19-
types::{FromS3Response, ListEntry, S3Request},
20-
utils::{
21-
from_iso8601utc, parse_tags, urldecode,
22-
xml::{Element, MergeXmlElements},
23-
},
24-
};
16+
use crate::s3::types::{FromS3Response, ListEntry, S3Request};
17+
use crate::s3::utils::xml::{Element, MergeXmlElements};
18+
use crate::s3::utils::{from_iso8601utc, parse_tags, urldecode};
2519
use async_trait::async_trait;
2620
use bytes::{Buf, Bytes};
2721
use reqwest::header::HeaderMap;

0 commit comments

Comments
 (0)