Skip to content

Commit a90ce17

Browse files
committed
Start CliTestContext type wrapper
1 parent 6eb71e9 commit a90ce17

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/test/mock/clitools.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{
1616

1717
use enum_map::{enum_map, Enum, EnumMap};
1818
use once_cell::sync::Lazy;
19+
use tempfile::TempDir;
1920
use tokio::runtime::Builder;
2021
use url::Url;
2122

@@ -302,25 +303,34 @@ pub fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDir,
302303
(test_dir, config)
303304
}
304305

305-
/// Run this to create the test environment containing rustup, and
306-
/// a mock dist server.
307306
pub fn test(s: Scenario, f: &dyn Fn(&mut Config)) {
308-
// Things we might cache or what not
307+
let mut cx = CliTestContext::from(s);
308+
f(&mut cx.config);
309+
}
310+
311+
pub struct CliTestContext {
312+
pub config: Config,
313+
_test_dir: TempDir,
314+
}
309315

310-
// Mutable dist server - working toward elimination
311-
let test_dist_dir = crate::test::test_dist_dir().unwrap();
312-
create_mock_dist_server(test_dist_dir.path(), s);
316+
impl From<Scenario> for CliTestContext {
317+
fn from(scenario: Scenario) -> Self {
318+
// Things we might cache or what not
313319

314-
// Things that are just about the test itself
315-
let (_test_dir, mut config) = setup_test_state(test_dist_dir);
316-
// Pulled out of setup_test_state for clarity: the long term intent is to
317-
// not have this at all.
318-
if s != Scenario::None {
319-
config.distdir = Some(config.test_dist_dir.path().to_path_buf());
320-
}
320+
// Mutable dist server - working toward elimination
321+
let test_dist_dir = crate::test::test_dist_dir().unwrap();
322+
create_mock_dist_server(test_dist_dir.path(), scenario);
321323

322-
// Run the test
323-
f(&mut config);
324+
// Things that are just about the test itself
325+
let (_test_dir, mut config) = setup_test_state(test_dist_dir);
326+
// Pulled out of setup_test_state for clarity: the long term intent is to
327+
// not have this at all.
328+
if scenario != Scenario::None {
329+
config.distdir = Some(config.test_dist_dir.path().to_path_buf());
330+
}
331+
332+
Self { config, _test_dir }
333+
}
324334
}
325335

326336
fn create_local_update_server(self_dist: &Path, exedir: &Path, version: &str) -> String {

0 commit comments

Comments
 (0)