Skip to content

Commit 3613999

Browse files
committed
Refactoring to call new generate_* functions instead of duplicating codes
1 parent 2a4d1dc commit 3613999

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,57 @@ use url::Url;
1515
/// initialized with a `config.json` file pointing to `dl_path` for downloads
1616
/// and `api_path` for uploads.
1717
pub fn registry_path() -> PathBuf {
18-
paths::root().join("registry")
18+
generate_path("registry")
1919
}
2020
pub fn registry_url() -> Url {
21-
Url::from_file_path(registry_path()).ok().unwrap()
21+
generate_url("registry")
2222
}
2323
/// Gets the path for local web API uploads. Cargo will place the contents of a web API
2424
/// request here. For example, `api/v1/crates/new` is the result of publishing a crate.
2525
pub fn api_path() -> PathBuf {
26-
paths::root().join("api")
26+
generate_path("api")
2727
}
2828
pub fn api_url() -> Url {
29-
Url::from_file_path(api_path()).ok().unwrap()
29+
generate_url("api")
3030
}
3131
/// Gets the path where crates can be downloaded using the web API endpoint. Crates
3232
/// should be organized as `{name}/{version}/download` to match the web API
3333
/// endpoint. This is rarely used and must be manually set up.
3434
pub fn dl_path() -> PathBuf {
35-
paths::root().join("dl")
35+
generate_path("dl")
3636
}
3737
pub fn dl_url() -> Url {
38-
Url::from_file_path(dl_path()).ok().unwrap()
38+
generate_url("dl")
3939
}
4040
/// Gets the alternative-registry version of `registry_path`.
4141
pub fn alt_registry_path() -> PathBuf {
42-
paths::root().join("alternative-registry")
42+
generate_path("alternative-registry")
4343
}
4444
pub fn alt_registry_url() -> Url {
45-
Url::from_file_path(alt_registry_path()).ok().unwrap()
45+
generate_url("alternative-registry")
4646
}
4747
/// Gets the alternative-registry version of `dl_path`.
4848
pub fn alt_dl_path() -> PathBuf {
49-
paths::root().join("alt_dl")
49+
generate_path("alt_dl")
5050
}
5151
pub fn alt_dl_url() -> String {
52-
let base = Url::from_file_path(alt_dl_path()).ok().unwrap();
53-
format!("{}/{{crate}}/{{version}}/{{crate}}-{{version}}.crate", base)
52+
generate_alt_dl_url("alt_dl")
5453
}
5554
/// Gets the alternative-registry version of `api_path`.
5655
pub fn alt_api_path() -> PathBuf {
57-
paths::root().join("alt_api")
56+
generate_path("alt_api")
5857
}
5958
pub fn alt_api_url() -> Url {
60-
Url::from_file_path(alt_api_path()).ok().unwrap()
59+
generate_url("alt_api")
6160
}
6261

63-
fn generate_path(name: &str) -> PathBuf {
62+
pub fn generate_path(name: &str) -> PathBuf {
6463
paths::root().join(name)
6564
}
6665
pub fn generate_url(name: &str) -> Url {
6766
Url::from_file_path(generate_path(name)).ok().unwrap()
6867
}
69-
fn generate_dl_url(name: &str) -> String {
68+
pub fn generate_alt_dl_url(name: &str) -> String {
7069
let base = Url::from_file_path(generate_path(name)).ok().unwrap();
7170
format!("{}/{{crate}}/{{version}}/{{crate}}-{{version}}.crate", base)
7271
}
@@ -234,7 +233,7 @@ pub fn init_alt2_registry() {
234233
r#"
235234
{{"dl":"{}","api":"{}"}}
236235
"#,
237-
generate_dl_url("alt2_dl"),
236+
generate_alt_dl_url("alt2_dl"),
238237
generate_url("alt2_api")
239238
),
240239
)

0 commit comments

Comments
 (0)