Skip to content

Commit

Permalink
test: remove separate default tests
Browse files Browse the repository at this point in the history
`set_var` may interfere with other tests, so we should set it in the
same test that uses it.
  • Loading branch information
wangl-cc committed Nov 25, 2023
1 parent 757db5a commit 4b53bd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 47 deletions.
48 changes: 19 additions & 29 deletions maa-cli/src/config/cli/maa_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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)
Expand All @@ -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/")
Expand Down
27 changes: 9 additions & 18 deletions maa-cli/src/config/cli/maa_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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);
Expand All @@ -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"
Expand Down

0 comments on commit 4b53bd7

Please sign in to comment.