Skip to content

Commit e05851c

Browse files
committed
重新调整测试用例,抽象测试工具 crate
1 parent b50113f commit e05851c

File tree

50 files changed

+530
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+530
-984
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[env]
22
TOKIO_WORKER_THREADS = "3"
3-
RUST_TEST_THREADS = "8"
3+
RUST_TEST_THREADS = "1"

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ which = "7.0.1"
7171
test-context = "0.3.0"
7272
uuid = "1.12.1"
7373

74+
# [profile.test]
75+
# test-threads = 1

crates/snm_config/src/env_snm_config.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod tests {
4242
#[test_context(SnmTestContext)]
4343
#[tokio::test]
4444
async fn should_parse_env_snm_config(ctx: &mut SnmTestContext) -> anyhow::Result<()> {
45-
let home_dir = ctx.temp_dir().to_string_lossy().to_string();
45+
let home_dir = ctx.get_temp_dir().to_string_lossy().to_string();
4646
let restricted_list = "install";
4747
let node_dist_url = "https://nodejs.org/dist";
4848
let node_github_resource_host = "https://raw.githubusercontent.com";
@@ -52,37 +52,37 @@ mod tests {
5252
let strict = true;
5353

5454
let envs = [
55-
(format!("{}_HOME_DIR", ctx.id()), home_dir.clone()),
55+
(format!("{}_HOME_DIR", ctx.get_id()), home_dir.clone()),
5656
(
57-
format!("{}_RESTRICTED_LIST", ctx.id()),
57+
format!("{}_RESTRICTED_LIST", ctx.get_id()),
5858
restricted_list.to_string(),
5959
),
6060
(
61-
format!("{}_NODE_DIST_URL", ctx.id()),
61+
format!("{}_NODE_DIST_URL", ctx.get_id()),
6262
node_dist_url.to_string(),
6363
),
6464
(
65-
format!("{}_NODE_GITHUB_RESOURCE_HOST", ctx.id()),
65+
format!("{}_NODE_GITHUB_RESOURCE_HOST", ctx.get_id()),
6666
node_github_resource_host.to_string(),
6767
),
6868
(
69-
format!("{}_NODE_WHITE_LIST", ctx.id()),
69+
format!("{}_NODE_WHITE_LIST", ctx.get_id()),
7070
node_white_list.to_string(),
7171
),
7272
(
73-
format!("{}_DOWNLOAD_TIMEOUT_SECS", ctx.id()),
73+
format!("{}_DOWNLOAD_TIMEOUT_SECS", ctx.get_id()),
7474
download_timeout_secs.to_string(),
7575
),
7676
(
77-
format!("{}_NPM_REGISTRY", ctx.id()),
77+
format!("{}_NPM_REGISTRY", ctx.get_id()),
7878
npm_registry.to_string(),
7979
),
80-
(format!("{}_STRICT", ctx.id()), strict.to_string()),
80+
(format!("{}_STRICT", ctx.get_id()), strict.to_string()),
8181
];
8282

83-
ctx.vars(&envs);
83+
ctx.set_envs(&envs);
8484

85-
let config = EnvSnmConfig::parse(ctx.id())?;
85+
let config = EnvSnmConfig::parse(ctx.get_id())?;
8686

8787
assert_eq!(config.home_dir, Some(home_dir.clone()));
8888
assert_eq!(config.restricted_list, Some(restricted_list.to_string()));

crates/snm_config/src/snm_config.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,24 @@ mod tests {
106106
#[test_context(SnmTestContext)]
107107
#[tokio::test]
108108
async fn should_parse_snm_config(ctx: &mut SnmTestContext) -> anyhow::Result<()> {
109-
ctx.vars(&[(
110-
format!("{}_HOME_DIR", ctx.id()),
111-
ctx.temp_dir().to_string_lossy().to_string(),
109+
ctx.set_envs(&[(
110+
format!("{}_HOME_DIR", ctx.get_id()),
111+
ctx.get_temp_dir().to_string_lossy().to_string(),
112112
)]);
113113

114-
let config = SnmConfig::from(ctx.id(), ctx.temp_dir())?;
114+
let config = SnmConfig::from(ctx.get_id(), ctx.get_temp_dir())?;
115115

116-
assert_eq!(config.node_bin_dir, ctx.temp_dir().join(".snm/node_bin"));
117-
assert_eq!(config.download_dir, ctx.temp_dir().join(".snm/downloads"));
116+
assert_eq!(
117+
config.node_bin_dir,
118+
ctx.get_temp_dir().join(".snm/node_bin")
119+
);
120+
assert_eq!(
121+
config.download_dir,
122+
ctx.get_temp_dir().join(".snm/downloads")
123+
);
118124
assert_eq!(
119125
config.node_modules_dir,
120-
ctx.temp_dir().join(".snm/node_modules")
126+
ctx.get_temp_dir().join(".snm/node_modules")
121127
);
122128
assert_eq!(config.node_dist_url, "https://nodejs.org/dist");
123129
assert_eq!(

crates/snm_npmrc/tests/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async fn should_read_custom_npm_registry(ctx: &mut SnmTestContext) -> anyhow::Re
2020
let prefix_unix = build_path(&current, &["tests", "fixtures", "global", "unix"]);
2121
let prefix_win = build_path(&current, &["tests", "fixtures", "global", "win"]);
2222

23-
ctx.vars(&[
23+
ctx.set_envs(&[
2424
("PREFIX".to_string(), prefix_unix),
2525
("APPDATA".to_string(), prefix_win),
2626
]);
@@ -44,7 +44,7 @@ async fn should_read_global_npm_cache(ctx: &mut SnmTestContext) -> anyhow::Resul
4444
let prefix_unix = build_path(&current, &["tests", "fixtures", "global", "unix"]);
4545
let prefix_win = build_path(&current, &["tests", "fixtures", "global", "win"]);
4646

47-
ctx.vars(&[
47+
ctx.set_envs(&[
4848
("PREFIX".to_string(), prefix_unix),
4949
("APPDATA".to_string(), prefix_win),
5050
]);
File renamed without changes.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"v0.8": {
3+
"start": "2012-06-25",
4+
"end": "2014-07-31"
5+
},
6+
"v0.10": {
7+
"start": "2013-03-11",
8+
"end": "2016-10-31"
9+
},
10+
"v0.12": {
11+
"start": "2015-02-06",
12+
"end": "2016-12-31"
13+
},
14+
"v4": {
15+
"start": "2015-09-08",
16+
"lts": "2015-10-12",
17+
"maintenance": "2017-04-01",
18+
"end": "2018-04-30",
19+
"codename": "Argon"
20+
},
21+
"v5": {
22+
"start": "2015-10-29",
23+
"maintenance": "2016-04-30",
24+
"end": "2016-06-30"
25+
},
26+
"v6": {
27+
"start": "2016-04-26",
28+
"lts": "2016-10-18",
29+
"maintenance": "2018-04-30",
30+
"end": "2019-04-30",
31+
"codename": "Boron"
32+
},
33+
"v7": {
34+
"start": "2016-10-25",
35+
"maintenance": "2017-04-30",
36+
"end": "2017-06-30"
37+
},
38+
"v8": {
39+
"start": "2017-05-30",
40+
"lts": "2017-10-31",
41+
"maintenance": "2019-01-01",
42+
"end": "2019-12-31",
43+
"codename": "Carbon"
44+
},
45+
"v9": {
46+
"start": "2017-10-01",
47+
"maintenance": "2018-04-01",
48+
"end": "2018-06-30"
49+
},
50+
"v10": {
51+
"start": "2018-04-24",
52+
"lts": "2018-10-30",
53+
"maintenance": "2020-05-19",
54+
"end": "2021-04-30",
55+
"codename": "Dubnium"
56+
},
57+
"v11": {
58+
"start": "2018-10-23",
59+
"maintenance": "2019-04-22",
60+
"end": "2019-06-01"
61+
},
62+
"v12": {
63+
"start": "2019-04-23",
64+
"lts": "2019-10-21",
65+
"maintenance": "2020-11-30",
66+
"end": "2022-04-30",
67+
"codename": "Erbium"
68+
},
69+
"v13": {
70+
"start": "2019-10-22",
71+
"maintenance": "2020-04-01",
72+
"end": "2020-06-01"
73+
},
74+
"v14": {
75+
"start": "2020-04-21",
76+
"lts": "2020-10-27",
77+
"maintenance": "2021-10-19",
78+
"end": "2023-04-30",
79+
"codename": "Fermium"
80+
},
81+
"v15": {
82+
"start": "2020-10-20",
83+
"maintenance": "2021-04-01",
84+
"end": "2021-06-01"
85+
},
86+
"v16": {
87+
"start": "2021-04-20",
88+
"lts": "2021-10-26",
89+
"maintenance": "2022-10-18",
90+
"end": "2023-09-11",
91+
"codename": "Gallium"
92+
},
93+
"v17": {
94+
"start": "2021-10-19",
95+
"maintenance": "2022-04-01",
96+
"end": "2022-06-01"
97+
},
98+
"v18": {
99+
"start": "2022-04-19",
100+
"lts": "2022-10-25",
101+
"maintenance": "2023-10-18",
102+
"end": "2025-04-30",
103+
"codename": "Hydrogen"
104+
},
105+
"v19": {
106+
"start": "2022-10-18",
107+
"maintenance": "2023-04-01",
108+
"end": "2023-06-01"
109+
},
110+
"v20": {
111+
"start": "2023-04-18",
112+
"lts": "2023-10-24",
113+
"maintenance": "2024-10-22",
114+
"end": "2026-04-30",
115+
"codename": "Iron"
116+
},
117+
"v21": {
118+
"start": "2023-10-17",
119+
"maintenance": "2024-04-01",
120+
"end": "2024-06-01"
121+
},
122+
"v22": {
123+
"start": "2024-04-24",
124+
"lts": "2024-10-29",
125+
"maintenance": "2025-10-21",
126+
"end": "2027-04-30",
127+
"codename": "Jod"
128+
},
129+
"v23": {
130+
"start": "2024-10-16",
131+
"maintenance": "2025-04-01",
132+
"end": "2025-06-01"
133+
},
134+
"v24": {
135+
"start": "2025-04-22",
136+
"lts": "2025-10-28",
137+
"maintenance": "2026-10-20",
138+
"end": "2028-04-30",
139+
"codename": ""
140+
}
141+
}
File renamed without changes.

e2e/src/fixtures/node/v20.0.0/node-v20.0.0-darwin-arm64.tar.xz renamed to crates/snm_test_utils/src/fixtures/node/v20.0.0/node-v20.0.0-darwin-arm64.tar.xz

File renamed without changes.

e2e/src/fixtures/node/v20.0.0/node-v20.0.0-darwin-x64.tar.xz renamed to crates/snm_test_utils/src/fixtures/node/v20.0.0/node-v20.0.0-darwin-x64.tar.xz

File renamed without changes.

0 commit comments

Comments
 (0)