From 4b53bd715db5633c8379079d1b5968b424aa2f12 Mon Sep 17 00:00:00 2001 From: Loong Date: Sun, 26 Nov 2023 02:01:47 +0800 Subject: [PATCH] test: remove separate default tests `set_var` may interfere with other tests, so we should set it in the same test that uses it. --- maa-cli/src/config/cli/maa_cli.rs | 48 ++++++++++++------------------ maa-cli/src/config/cli/maa_core.rs | 27 ++++++----------- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/maa-cli/src/config/cli/maa_cli.rs b/maa-cli/src/config/cli/maa_cli.rs index 2b609551..52c866b8 100644 --- a/maa-cli/src/config/cli/maa_cli.rs +++ b/maa-cli/src/config/cli/maa_cli.rs @@ -160,39 +160,11 @@ mod tests { } } - mod default { + mod methods { use super::*; use std::env::{remove_var, set_var}; - #[test] - fn api_url() { - assert_eq!( - default_api_url(), - "https://github.com/MaaAssistantArknights/maa-cli/raw/version/" - ); - - set_var("MAA_CLI_API", "https://foo.bar/cli/"); - assert_eq!(default_api_url(), "https://foo.bar/cli/"); - remove_var("MAA_CLI_API"); - } - - #[test] - fn download_url() { - assert_eq!( - default_download_url(), - "https://github.com/MaaAssistantArknights/maa-cli/releases/download/", - ); - - set_var("MAA_CLI_DOWNLOAD", "https://foo.bar/download/"); - assert_eq!(default_download_url(), "https://foo.bar/download/"); - remove_var("MAA_CLI_DOWNLOAD"); - } - } - - mod methods { - use super::*; - #[test] fn channel() { assert_eq!(Config::default().channel(), Default::default()); @@ -208,6 +180,14 @@ mod tests { Config::default().api_url(), "https://github.com/MaaAssistantArknights/maa-cli/raw/version/stable.json", ); + + set_var("MAA_CLI_API", "https://foo.bar/cli/"); + assert_eq!( + Config::default().api_url(), + "https://foo.bar/cli/stable.json", + ); + remove_var("MAA_CLI_API"); + assert_eq!( Config::default() .with_channel(Channel::Alpha) @@ -219,10 +199,20 @@ mod tests { #[test] fn download_url() { + set_var("MAA_CLI_DOWNLOAD", "https://foo.bar/download/"); + assert_eq!( + Config::default() + .with_download_url("https://foo.bar/download/") + .download_url("v0.3.12", "maa_cli.zip"), + "https://foo.bar/download/v0.3.12/maa_cli.zip", + ); + remove_var("MAA_CLI_DOWNLOAD"); + assert_eq!( Config::default().download_url("v0.3.12", "maa_cli.zip"), "https://github.com/MaaAssistantArknights/maa-cli/releases/download/v0.3.12/maa_cli.zip", ); + assert_eq!( Config::default() .with_download_url("https://foo.bar/download/") diff --git a/maa-cli/src/config/cli/maa_core.rs b/maa-cli/src/config/cli/maa_core.rs index 8ddc9269..145c22f0 100644 --- a/maa-cli/src/config/cli/maa_core.rs +++ b/maa-cli/src/config/cli/maa_core.rs @@ -182,24 +182,6 @@ mod tests { } } - mod default { - use super::*; - - use std::env::{remove_var, set_var}; - - #[test] - fn api_url() { - assert_eq!( - default_api_url(), - "https://ota.maa.plus/MaaAssistantArknights/api/version/" - ); - - set_var("MAA_API_URL", "https://foo.bar/core/"); - assert_eq!(default_api_url(), "https://foo.bar/core/"); - remove_var("MAA_API_URL"); - } - } - mod serde { use super::*; @@ -279,6 +261,8 @@ mod tests { mod methods { use super::*; + use std::env::{remove_var, set_var}; + #[test] fn channel() { assert_eq!(Config::default().channel(), Channel::Stable); @@ -294,6 +278,13 @@ mod tests { #[test] fn api_url() { + set_var("MAA_API_URL", "https://foo.bar/core/"); + assert_eq!( + Config::default().api_url(), + "https://foo.bar/core/stable.json" + ); + remove_var("MAA_API_URL"); + assert_eq!( Config::default().api_url(), "https://ota.maa.plus/MaaAssistantArknights/api/version/stable.json"