Skip to content

Commit e58f9da

Browse files
committed
Fix removed_component test
1 parent dd29663 commit e58f9da

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

src/dist/manifestation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Manifestation {
123123
let update = Update::build_update(self, new_manifest, &changes, &config, notify_handler)?;
124124

125125
if update.nothing_changes() {
126-
// TODO chnages and ,manifest are empty?
126+
// TODO changes and ,manifest are empty?
127127
eprintln!("update: {:?}", update);
128128
return Ok(UpdateStatus::Unchanged);
129129
}

tests/dist.rs

+21-30
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tempdir::TempDir;
2828
// Creates a mock dist server populated with some test data
2929
pub fn create_mock_dist_server(
3030
path: &Path,
31-
edit: Option<&dyn Fn(&str, &mut [MockPackage])>,
31+
edit: Option<&dyn Fn(&str, &mut Vec<MockPackage>)>,
3232
) -> MockDistServer {
3333
MockDistServer {
3434
path: path.to_owned(),
@@ -42,7 +42,7 @@ pub fn create_mock_dist_server(
4242
pub fn create_mock_channel(
4343
channel: &str,
4444
date: &str,
45-
edit: Option<&dyn Fn(&str, &mut [MockPackage])>,
45+
edit: Option<&dyn Fn(&str, &mut Vec<MockPackage>)>,
4646
) -> MockChannel {
4747
// Put the date in the files so they can be differentiated
4848
let contents = Arc::new(date.as_bytes().to_vec());
@@ -303,7 +303,7 @@ fn rename_component() {
303303
let dist_tempdir = TempDir::new("rustup").unwrap();
304304
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
305305

306-
let edit_1 = &|_: &str, pkgs: &mut [MockPackage]| {
306+
let edit_1 = &|_: &str, pkgs: &mut Vec<MockPackage>| {
307307
let tpkg = pkgs[0]
308308
.targets
309309
.iter_mut()
@@ -314,7 +314,7 @@ fn rename_component() {
314314
target: "x86_64-apple-darwin".to_string(),
315315
});
316316
};
317-
let edit_2 = &|_: &str, pkgs: &mut [MockPackage]| {
317+
let edit_2 = &|_: &str, pkgs: &mut Vec<MockPackage>| {
318318
let tpkg = pkgs[0]
319319
.targets
320320
.iter_mut()
@@ -363,7 +363,7 @@ fn rename_component_new() {
363363
let dist_tempdir = TempDir::new("rustup").unwrap();
364364
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
365365

366-
let edit_2 = &|_: &str, pkgs: &mut [MockPackage]| {
366+
let edit_2 = &|_: &str, pkgs: &mut Vec<MockPackage>| {
367367
let tpkg = pkgs[0]
368368
.targets
369369
.iter_mut()
@@ -498,7 +498,7 @@ fn uninstall(
498498
}
499499

500500
fn setup(
501-
edit: Option<&dyn Fn(&str, &mut [MockPackage])>,
501+
edit: Option<&dyn Fn(&str, &mut Vec<MockPackage>)>,
502502
enable_xz: bool,
503503
f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg),
504504
) {
@@ -623,7 +623,7 @@ fn upgrade() {
623623
#[test]
624624
fn unavailable_component() {
625625
// On day 2 the bonus component is no longer available
626-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
626+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
627627
// Require the bonus component every dat
628628
{
629629
let tpkg = pkgs[0]
@@ -671,7 +671,7 @@ fn unavailable_component() {
671671
#[test]
672672
fn removed_component() {
673673
// On day 1 install the 'bonus' component, on day 2 its no longer a component
674-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
674+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
675675
if date == "2016-02-01" {
676676
let tpkg = pkgs[0]
677677
.targets
@@ -682,37 +682,28 @@ fn removed_component() {
682682
name: "bonus".to_string(),
683683
target: "x86_64-apple-darwin".to_string(),
684684
});
685+
} else {
686+
pkgs.retain(|p| p.name != "bonus");
685687
}
686688
};
687689

688690
setup(
689691
Some(edit),
690692
false,
691693
&|url, toolchain, prefix, download_cfg, temp_cfg| {
692-
let received_notification = Arc::new(Cell::new(false));
693-
694-
let download_cfg = DownloadCfg {
695-
dist_root: download_cfg.dist_root,
696-
temp_cfg: download_cfg.temp_cfg,
697-
download_dir: download_cfg.download_dir,
698-
notify_handler: &|n| {
699-
if let Notification::ComponentUnavailable("bonus", Some(_)) = n {
700-
received_notification.set(true);
701-
}
702-
},
703-
};
694+
let adds = [Component::new(
695+
"bonus".to_string(),
696+
Some(TargetTriple::from_str("x86_64-apple-darwin")),
697+
)];
704698

705-
change_channel_date(url, "nightly", "2016-02-01");
706699
// Update with bonus.
707-
update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap();
700+
change_channel_date(url, "nightly", "2016-02-01");
701+
update_from_dist(url, toolchain, prefix, &adds, &[], &download_cfg, temp_cfg).unwrap();
708702
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
709-
change_channel_date(url, "nightly", "2016-02-02");
710703

711704
// Update without bonus, should emit a notify and remove the bonus component
712-
update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap();
713-
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
714-
715-
assert!(received_notification.get());
705+
change_channel_date(url, "nightly", "2016-02-02");
706+
assert!(update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).is_err());
716707
},
717708
);
718709
}
@@ -759,7 +750,7 @@ fn update_preserves_extensions() {
759750

760751
#[test]
761752
fn update_preserves_extensions_that_became_components() {
762-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
753+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
763754
if date == "2016-02-01" {
764755
let tpkg = pkgs[0]
765756
.targets
@@ -806,7 +797,7 @@ fn update_preserves_extensions_that_became_components() {
806797

807798
#[test]
808799
fn update_preserves_components_that_became_extensions() {
809-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
800+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
810801
if date == "2016-02-01" {
811802
let tpkg = pkgs[0]
812803
.targets
@@ -1139,7 +1130,7 @@ fn remove_extension_not_in_manifest() {
11391130
#[test]
11401131
#[should_panic]
11411132
fn remove_extension_not_in_manifest_but_is_already_installed() {
1142-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
1133+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
11431134
if date == "2016-02-01" {
11441135
let tpkg = pkgs[0]
11451136
.targets

0 commit comments

Comments
 (0)