From 0329ac75709a66da7b0514de6274b97a00638a8d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sun, 19 May 2019 21:52:47 +1200 Subject: [PATCH] Fix removed_component test --- src/dist/manifestation.rs | 8 +++++++- tests/dist.rs | 41 ++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index 51b62f90ae..aad013571b 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -123,7 +123,7 @@ impl Manifestation { let update = Update::build_update(self, new_manifest, &changes, &config, notify_handler)?; if update.nothing_changes() { - // TODO chnages and ,manifest are empty? + // TODO changes and ,manifest are empty? eprintln!("update: {:?}", update); return Ok(UpdateStatus::Unchanged); } @@ -502,6 +502,7 @@ impl Update { new_manifest, &changes, config, + notify_handler, ); // If this is a full upgrade then the list of components to @@ -548,6 +549,7 @@ impl Update { new_manifest: &Manifest, changes: &Changes, config: &Option, + notify_handler: &dyn Fn(Notification<'_>), ) { // Add requested components for component in &changes.explicit_add_components { @@ -588,6 +590,10 @@ impl Update { self.final_component_list.push(existing_component.clone()); } else { self.missing_components.push(existing_component.clone()); + notify_handler(Notification::ComponentUnavailable( + &existing_component.short_name(new_manifest), + existing_component.target.as_ref(), + )); } } } diff --git a/tests/dist.rs b/tests/dist.rs index 4130aa770b..d4dec0e5b0 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -28,7 +28,7 @@ use tempdir::TempDir; // Creates a mock dist server populated with some test data pub fn create_mock_dist_server( path: &Path, - edit: Option<&dyn Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut Vec)>, ) -> MockDistServer { MockDistServer { path: path.to_owned(), @@ -42,7 +42,7 @@ pub fn create_mock_dist_server( pub fn create_mock_channel( channel: &str, date: &str, - edit: Option<&dyn Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut Vec)>, ) -> MockChannel { // Put the date in the files so they can be differentiated let contents = Arc::new(date.as_bytes().to_vec()); @@ -303,7 +303,7 @@ fn rename_component() { let dist_tempdir = TempDir::new("rustup").unwrap(); let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); - let edit_1 = &|_: &str, pkgs: &mut [MockPackage]| { + let edit_1 = &|_: &str, pkgs: &mut Vec| { let tpkg = pkgs[0] .targets .iter_mut() @@ -314,7 +314,7 @@ fn rename_component() { target: "x86_64-apple-darwin".to_string(), }); }; - let edit_2 = &|_: &str, pkgs: &mut [MockPackage]| { + let edit_2 = &|_: &str, pkgs: &mut Vec| { let tpkg = pkgs[0] .targets .iter_mut() @@ -363,7 +363,7 @@ fn rename_component_new() { let dist_tempdir = TempDir::new("rustup").unwrap(); let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); - let edit_2 = &|_: &str, pkgs: &mut [MockPackage]| { + let edit_2 = &|_: &str, pkgs: &mut Vec| { let tpkg = pkgs[0] .targets .iter_mut() @@ -498,7 +498,7 @@ fn uninstall( } fn setup( - edit: Option<&dyn Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut Vec)>, enable_xz: bool, f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg), ) { @@ -623,7 +623,7 @@ fn upgrade() { #[test] fn unavailable_component() { // On day 2 the bonus component is no longer available - let edit = &|date: &str, pkgs: &mut [MockPackage]| { + let edit = &|date: &str, pkgs: &mut Vec| { // Require the bonus component every dat { let tpkg = pkgs[0] @@ -671,7 +671,7 @@ fn unavailable_component() { #[test] fn removed_component() { // On day 1 install the 'bonus' component, on day 2 its no longer a component - let edit = &|date: &str, pkgs: &mut [MockPackage]| { + let edit = &|date: &str, pkgs: &mut Vec| { if date == "2016-02-01" { let tpkg = pkgs[0] .targets @@ -682,6 +682,8 @@ fn removed_component() { name: "bonus".to_string(), target: "x86_64-apple-darwin".to_string(), }); + } else { + pkgs.retain(|p| p.name != "bonus"); } }; @@ -702,17 +704,20 @@ fn removed_component() { }, }; - change_channel_date(url, "nightly", "2016-02-01"); + let adds = [Component::new( + "bonus".to_string(), + Some(TargetTriple::from_str("x86_64-apple-darwin")), + )]; + // Update with bonus. - update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap(); + change_channel_date(url, "nightly", "2016-02-01"); + update_from_dist(url, toolchain, prefix, &adds, &[], &download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/bonus"))); - change_channel_date(url, "nightly", "2016-02-02"); + assert!(!received_notification.get()); // Update without bonus, should emit a notify and remove the bonus component - update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap(); - assert!(!utils::path_exists(&prefix.path().join("bin/bonus"))); - - assert!(received_notification.get()); + change_channel_date(url, "nightly", "2016-02-02"); + assert!(update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).is_err()); }, ); } @@ -759,7 +764,7 @@ fn update_preserves_extensions() { #[test] fn update_preserves_extensions_that_became_components() { - let edit = &|date: &str, pkgs: &mut [MockPackage]| { + let edit = &|date: &str, pkgs: &mut Vec| { if date == "2016-02-01" { let tpkg = pkgs[0] .targets @@ -806,7 +811,7 @@ fn update_preserves_extensions_that_became_components() { #[test] fn update_preserves_components_that_became_extensions() { - let edit = &|date: &str, pkgs: &mut [MockPackage]| { + let edit = &|date: &str, pkgs: &mut Vec| { if date == "2016-02-01" { let tpkg = pkgs[0] .targets @@ -1139,7 +1144,7 @@ fn remove_extension_not_in_manifest() { #[test] #[should_panic] fn remove_extension_not_in_manifest_but_is_already_installed() { - let edit = &|date: &str, pkgs: &mut [MockPackage]| { + let edit = &|date: &str, pkgs: &mut Vec| { if date == "2016-02-01" { let tpkg = pkgs[0] .targets