From 02fc844e40179909760a31c4ebd12bf5ea354e73 Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Fri, 20 Dec 2024 00:15:27 +0100 Subject: [PATCH] Fix `commands::network::http::*::*_timeout` tests on non-english system (#14640) # Description I had issues with the following tests: - `commands::network::http::delete::http_delete_timeout` - `commands::network::http::get::http_get_timeout` - `commands::network::http::options::http_options_timeout` - `commands::network::http::patch::http_patch_timeout` - `commands::network::http::post::http_post_timeout` - `commands::network::http::put::http_put_timeout` I checked what the actual issue was and my problem was that the tested string `"did not properly respond after a period of time"` wasn't in the actual error. This happened because my german Windows would return a german error message which obviosly did not include that string. To fix that I replaced the string check with the os error code that is also part of the error message which should be language agnostic. (I hope.) # User-Facing Changes None. # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` \o/ # After Submitting --- .../nu-command/tests/commands/network/http/delete.rs | 4 +--- crates/nu-command/tests/commands/network/http/get.rs | 4 +--- crates/nu-command/tests/commands/network/http/mod.rs | 11 +++++++++++ .../nu-command/tests/commands/network/http/options.rs | 4 +--- .../nu-command/tests/commands/network/http/patch.rs | 4 +--- crates/nu-command/tests/commands/network/http/post.rs | 4 +--- crates/nu-command/tests/commands/network/http/put.rs | 4 +--- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/crates/nu-command/tests/commands/network/http/delete.rs b/crates/nu-command/tests/commands/network/http/delete.rs index ac79a4fe62..ec466944de 100644 --- a/crates/nu-command/tests/commands/network/http/delete.rs +++ b/crates/nu-command/tests/commands/network/http/delete.rs @@ -145,7 +145,5 @@ fn http_delete_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); } diff --git a/crates/nu-command/tests/commands/network/http/get.rs b/crates/nu-command/tests/commands/network/http/get.rs index 87b6b93388..a4245ee4db 100644 --- a/crates/nu-command/tests/commands/network/http/get.rs +++ b/crates/nu-command/tests/commands/network/http/get.rs @@ -339,7 +339,5 @@ fn http_get_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); } diff --git a/crates/nu-command/tests/commands/network/http/mod.rs b/crates/nu-command/tests/commands/network/http/mod.rs index 4a96a9c5ea..07a042f674 100644 --- a/crates/nu-command/tests/commands/network/http/mod.rs +++ b/crates/nu-command/tests/commands/network/http/mod.rs @@ -5,3 +5,14 @@ mod options; mod patch; mod post; mod put; + +/// String representation of the Windows error code for timeouts on slow links. +/// +/// Use this constant in tests instead of matching partial error message content, +/// such as `"did not properly respond after a period of time"`, which can vary by language. +/// The specific string `"(os error 10060)"` is consistent across all locales, as it represents +/// the raw error code rather than localized text. +/// +/// For more details, see the [Microsoft docs](https://learn.microsoft.com/en-us/troubleshoot/windows-client/networking/10060-connection-timed-out-with-proxy-server). +#[cfg(all(test, windows))] +const WINDOWS_ERROR_TIMEOUT_SLOW_LINK: &str = "(os error 10060)"; diff --git a/crates/nu-command/tests/commands/network/http/options.rs b/crates/nu-command/tests/commands/network/http/options.rs index b1478b4ecc..cbe9c7bd8e 100644 --- a/crates/nu-command/tests/commands/network/http/options.rs +++ b/crates/nu-command/tests/commands/network/http/options.rs @@ -64,7 +64,5 @@ fn http_options_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); } diff --git a/crates/nu-command/tests/commands/network/http/patch.rs b/crates/nu-command/tests/commands/network/http/patch.rs index 90788f6769..660f335864 100644 --- a/crates/nu-command/tests/commands/network/http/patch.rs +++ b/crates/nu-command/tests/commands/network/http/patch.rs @@ -189,7 +189,5 @@ fn http_patch_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); } diff --git a/crates/nu-command/tests/commands/network/http/post.rs b/crates/nu-command/tests/commands/network/http/post.rs index 2b238573fa..99ef44acaf 100644 --- a/crates/nu-command/tests/commands/network/http/post.rs +++ b/crates/nu-command/tests/commands/network/http/post.rs @@ -303,7 +303,5 @@ fn http_post_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); } diff --git a/crates/nu-command/tests/commands/network/http/put.rs b/crates/nu-command/tests/commands/network/http/put.rs index 41a4bf7848..3f3bae3998 100644 --- a/crates/nu-command/tests/commands/network/http/put.rs +++ b/crates/nu-command/tests/commands/network/http/put.rs @@ -189,7 +189,5 @@ fn http_put_timeout() { #[cfg(not(target_os = "windows"))] assert!(&actual.err.contains("timed out reading response")); #[cfg(target_os = "windows")] - assert!(&actual - .err - .contains("did not properly respond after a period of time")); + assert!(&actual.err.contains(super::WINDOWS_ERROR_TIMEOUT_SLOW_LINK)); }