Skip to content

Commit 0329ac7

Browse files
committed
Fix removed_component test
1 parent dd29663 commit 0329ac7

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/dist/manifestation.rs

+7-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
}
@@ -502,6 +502,7 @@ impl Update {
502502
new_manifest,
503503
&changes,
504504
config,
505+
notify_handler,
505506
);
506507

507508
// If this is a full upgrade then the list of components to
@@ -548,6 +549,7 @@ impl Update {
548549
new_manifest: &Manifest,
549550
changes: &Changes,
550551
config: &Option<Config>,
552+
notify_handler: &dyn Fn(Notification<'_>),
551553
) {
552554
// Add requested components
553555
for component in &changes.explicit_add_components {
@@ -588,6 +590,10 @@ impl Update {
588590
self.final_component_list.push(existing_component.clone());
589591
} else {
590592
self.missing_components.push(existing_component.clone());
593+
notify_handler(Notification::ComponentUnavailable(
594+
&existing_component.short_name(new_manifest),
595+
existing_component.target.as_ref(),
596+
));
591597
}
592598
}
593599
}

tests/dist.rs

+23-18
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,6 +682,8 @@ 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

@@ -702,17 +704,20 @@ fn removed_component() {
702704
},
703705
};
704706

705-
change_channel_date(url, "nightly", "2016-02-01");
707+
let adds = [Component::new(
708+
"bonus".to_string(),
709+
Some(TargetTriple::from_str("x86_64-apple-darwin")),
710+
)];
711+
706712
// Update with bonus.
707-
update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap();
713+
change_channel_date(url, "nightly", "2016-02-01");
714+
update_from_dist(url, toolchain, prefix, &adds, &[], &download_cfg, temp_cfg).unwrap();
708715
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
709-
change_channel_date(url, "nightly", "2016-02-02");
716+
assert!(!received_notification.get());
710717

711718
// 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());
719+
change_channel_date(url, "nightly", "2016-02-02");
720+
assert!(update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).is_err());
716721
},
717722
);
718723
}
@@ -759,7 +764,7 @@ fn update_preserves_extensions() {
759764

760765
#[test]
761766
fn update_preserves_extensions_that_became_components() {
762-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
767+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
763768
if date == "2016-02-01" {
764769
let tpkg = pkgs[0]
765770
.targets
@@ -806,7 +811,7 @@ fn update_preserves_extensions_that_became_components() {
806811

807812
#[test]
808813
fn update_preserves_components_that_became_extensions() {
809-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
814+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
810815
if date == "2016-02-01" {
811816
let tpkg = pkgs[0]
812817
.targets
@@ -1139,7 +1144,7 @@ fn remove_extension_not_in_manifest() {
11391144
#[test]
11401145
#[should_panic]
11411146
fn remove_extension_not_in_manifest_but_is_already_installed() {
1142-
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
1147+
let edit = &|date: &str, pkgs: &mut Vec<MockPackage>| {
11431148
if date == "2016-02-01" {
11441149
let tpkg = pkgs[0]
11451150
.targets

0 commit comments

Comments
 (0)