From 80d1acf295a365736e5d6f31171614a5c2178e56 Mon Sep 17 00:00:00 2001 From: Anthony Oteri Date: Mon, 2 Oct 2023 13:01:58 -0400 Subject: [PATCH 1/2] Replace async-std with tokio Tokio is a far more mature async runtime. --- Cargo.toml | 4 ++-- src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccc7e37..75931f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ categories = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-std = { version = "1.12.0", features = ["async-attributes", "attributes", "tokio1"] } clap = { version = "4.4.3", features = ["derive", "env", "wrap_help"] } simple_logger = { version = "4.2.0", features = ["timestamps", "colors", "stderr"] } http = "0.2.9" @@ -35,7 +34,8 @@ thiserror = "1.0.48" toml = "0.8.0" url = { version = "2.4.1", features = ["serde"] } xdg = "2.5.2" +tokio = { version = "1.32.0", features = ["macros"] } [dev-dependencies] mockito = "1.2.0" -env_logger = "0.10.0" \ No newline at end of file +env_logger = "0.10.0" diff --git a/src/main.rs b/src/main.rs index 8b88f2e..a7a6c6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ fn parse_registry_arg(host: &str) -> Result { Url::parse(&host).or(Err(DredgeError::RegistryUrlError(host.to_string()))) } -#[async_std::main] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), DredgeError> { let args = Cli::parse(); From 42f8f46bd32a87a288c52ba6e8fd438f36c07719 Mon Sep 17 00:00:00 2001 From: Anthony Oteri Date: Mon, 2 Oct 2023 13:10:55 -0400 Subject: [PATCH 2/2] Replace async_std::test with tokio::test --- src/api.rs | 6 +++--- src/commands.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api.rs b/src/api.rs index 9827b0e..599a448 100644 --- a/src/api.rs +++ b/src/api.rs @@ -207,7 +207,7 @@ mod tests { /// /// Attempt to parse a valid RFC5988 header value, and ensure that the /// parsed URL was returned as expected. - #[async_std::test] + #[tokio::test] async fn test_parse_rfc5988_valid() { // Mock a valid RFC5988 header value let valid_header_value = @@ -225,7 +225,7 @@ mod tests { /// /// Attempt to parse an invalid string as RFC5988, ensuring that the `None` /// variant is returned. - #[async_std::test] + #[tokio::test] async fn test_parse_rfc5988_invalid() { // Mock a valid RFC5988 header value let invalid_header_value = HeaderValue::from_str(r#"invalid header value"#) @@ -244,7 +244,7 @@ mod tests { /// the digest with the proper headers set. The test then validates that /// the correct digest is returned and that the mock server had the expected /// interactions. - #[async_std::test] + #[tokio::test] async fn test_get_digest() -> Result<(), ApiError> { let mut server = mockito::Server::new_async().await; let path = "/v2/foo/manifests/latest"; diff --git a/src/commands.rs b/src/commands.rs index 9ad39fb..318f863 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -224,7 +224,7 @@ mod tests { /// This test spins up a mock server, and makes a request to the catalog /// endpoint. It checks that the handler both called the request the /// expected number of times, and did not return an error. - #[async_std::test] + #[tokio::test] async fn test_catalog_handler() { let mut server = mockito::Server::new_async().await; let path = "/v2/_catalog"; @@ -253,7 +253,7 @@ mod tests { /// should follow, resulting in the combined list. It checks that the /// handler both called the request the expected number of times, and did /// not return an error. - #[async_std::test] + #[tokio::test] async fn test_catalog_handler_with_pagination() { let mut server = mockito::Server::new_async().await; let path = "/v2/_catalog"; @@ -294,7 +294,7 @@ mod tests { /// This test spins up a mock server, and makes a request to the tags /// endpoint. It checks that the handler both called the request the /// expected number of times, and did not return an error. - #[async_std::test] + #[tokio::test] async fn test_tags_handler() { let mut server = mockito::Server::new_async().await; let path = "/v2/some_image/tags/list"; @@ -324,7 +324,7 @@ mod tests { /// should follow, resulting in the combined list. It checks that the /// handler both called the request the expected number of times, and did /// not return an error. - #[async_std::test] + #[tokio::test] async fn test_tags_handler_with_pagination() { let mut server = mockito::Server::new_async().await; let path = "/v2/some_image/tags/list"; @@ -366,7 +366,7 @@ mod tests { /// This test spins up a mock server, and makes a request to the check /// endpoint. It checks that the handler both called the request the /// expected number of times, and did not return an error. - #[async_std::test] + #[tokio::test] async fn test_check_handler() { let mut server = mockito::Server::new_async().await; let path = "/v2"; @@ -392,7 +392,7 @@ mod tests { /// /// This validates that if the "Docker-Distribution-API-Version" header /// is missing in the response, the appropriate error is returned. - #[async_std::test] + #[tokio::test] async fn test_check_handler_missing_api_version() -> Result<(), Box> { let mut server = mockito::Server::new_async().await; let path = "/v2"; @@ -425,7 +425,7 @@ mod tests { /// This validates that if the "Docker-Distribution-API-Version" header /// is present in the response but contains an unexpected value, the /// appropriate error is returned. - #[async_std::test] + #[tokio::test] async fn test_check_handler_invalid_api_version() -> Result<(), Box> { let mut server = mockito::Server::new_async().await; let path = "/v2"; @@ -459,7 +459,7 @@ mod tests { /// This test spins up a mock server, and makes a request to the image /// manifests endpoint. It checks that the handler both called the request /// the expected number of times, and did not return an error. - #[async_std::test] + #[tokio::test] async fn test_show_handler() { let mut server = mockito::Server::new_async().await; let path = "/v2/foo/manifests/latest";