Skip to content

Commit

Permalink
Refactoring of creating registry
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Dec 17, 2019
1 parent 3613999 commit b7bc069
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
49 changes: 17 additions & 32 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,51 +194,36 @@ pub fn init() {
));

// Initialize a new registry.
let _ = repo(&registry_path())
.file(
"config.json",
&format!(
r#"
{{"dl":"{}","api":"{}"}}
"#,
dl_url(),
api_url()
),
)
.build();
fs::create_dir_all(api_path().join("api/v1/crates")).unwrap();
init_registry(
registry_path(),
dl_url().into_string(),
api_url(),
api_path(),
);

// Initialize an alternative registry.
repo(&alt_registry_path())
.file(
"config.json",
&format!(
r#"
{{"dl":"{}","api":"{}"}}
"#,
alt_dl_url(),
alt_api_url()
),
)
.build();
fs::create_dir_all(alt_api_path().join("api/v1/crates")).unwrap();
init_registry(
alt_registry_path(),
alt_dl_url(),
alt_api_url(),
alt_api_path(),
);
}

pub fn init_alt2_registry() {
// Initialize an alternative2 registry.
repo(&generate_path("alternative2-registry"))
pub fn init_registry(registry_path: PathBuf, dl_url: String, api_url: Url, api_path: PathBuf) {
// Initialize a new registry.
repo(&registry_path)
.file(
"config.json",
&format!(
r#"
{{"dl":"{}","api":"{}"}}
"#,
generate_alt_dl_url("alt2_dl"),
generate_url("alt2_api")
dl_url, api_url
),
)
.build();
fs::create_dir_all(generate_path("alt2_api").join("api/v1/crates")).unwrap();
fs::create_dir_all(api_path.join("api/v1/crates")).unwrap();
}

impl Package {
Expand Down
7 changes: 6 additions & 1 deletion tests/testsuite/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ fn registry_credentials() {
.as_bytes(),
));

registry::init_alt2_registry();
registry::init_registry(
registry::generate_path("alternative2-registry"),
registry::generate_alt_dl_url("alt2_dl"),
registry::generate_url("alt2_api"),
registry::generate_path("alt2_api"),
);
setup_new_credentials();

let reg = "alternative";
Expand Down

0 comments on commit b7bc069

Please sign in to comment.