Skip to content

Commit b3ac2c9

Browse files
committed
test(dist/manifestation): extract TestContext::*with_env()
1 parent feca83a commit b3ac2c9

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/dist/manifestation/tests.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,33 @@ struct TestContext {
417417

418418
impl TestContext {
419419
fn new(edit: Option<&dyn Fn(&str, &mut MockChannel)>, comps: Compressions) -> Self {
420+
Self::with_env(edit, comps, HashMap::new())
421+
}
422+
423+
fn with_env(
424+
edit: Option<&dyn Fn(&str, &mut MockChannel)>,
425+
comps: Compressions,
426+
env: HashMap<String, String>,
427+
) -> Self {
420428
let dist_tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
421429
let mock_dist_server = create_mock_dist_server(dist_tempdir.path(), edit);
422430
let url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
423431

424-
let mut cx = Self::from_dist_server(mock_dist_server, url, comps);
432+
let mut cx = Self::from_dist_server_with_env(mock_dist_server, url, comps, env);
425433
cx._tempdirs.push(dist_tempdir);
426434
cx
427435
}
428436

429437
fn from_dist_server(server: MockDistServer, url: Url, comps: Compressions) -> Self {
438+
Self::from_dist_server_with_env(server, url, comps, HashMap::new())
439+
}
440+
441+
fn from_dist_server_with_env(
442+
server: MockDistServer,
443+
url: Url,
444+
comps: Compressions,
445+
env: HashMap<String, String>,
446+
) -> Self {
430447
server.write(
431448
&[MockManifestVersion::V2],
432449
comps.enable_xz(),
@@ -444,12 +461,7 @@ impl TestContext {
444461

445462
let toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap();
446463
let prefix = InstallPrefix::from(prefix_tempdir.path());
447-
let tp = TestProcess::new(
448-
env::current_dir().unwrap(),
449-
&["rustup"],
450-
HashMap::default(),
451-
"",
452-
);
464+
let tp = TestProcess::new(env::current_dir().unwrap(), &["rustup"], env, "");
453465

454466
Self {
455467
url,

0 commit comments

Comments
 (0)