Skip to content

Commit

Permalink
Fix removed_component test
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 19, 2019
1 parent dd29663 commit 0329ac7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -502,6 +502,7 @@ impl Update {
new_manifest,
&changes,
config,
notify_handler,
);

// If this is a full upgrade then the list of components to
Expand Down Expand Up @@ -548,6 +549,7 @@ impl Update {
new_manifest: &Manifest,
changes: &Changes,
config: &Option<Config>,
notify_handler: &dyn Fn(Notification<'_>),
) {
// Add requested components
for component in &changes.explicit_add_components {
Expand Down Expand Up @@ -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(),
));
}
}
}
Expand Down
41 changes: 23 additions & 18 deletions tests/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MockPackage>)>,
) -> MockDistServer {
MockDistServer {
path: path.to_owned(),
Expand All @@ -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<MockPackage>)>,
) -> MockChannel {
// Put the date in the files so they can be differentiated
let contents = Arc::new(date.as_bytes().to_vec());
Expand Down Expand Up @@ -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<MockPackage>| {
let tpkg = pkgs[0]
.targets
.iter_mut()
Expand All @@ -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<MockPackage>| {
let tpkg = pkgs[0]
.targets
.iter_mut()
Expand Down Expand Up @@ -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<MockPackage>| {
let tpkg = pkgs[0]
.targets
.iter_mut()
Expand Down Expand Up @@ -498,7 +498,7 @@ fn uninstall(
}

fn setup(
edit: Option<&dyn Fn(&str, &mut [MockPackage])>,
edit: Option<&dyn Fn(&str, &mut Vec<MockPackage>)>,
enable_xz: bool,
f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg),
) {
Expand Down Expand Up @@ -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<MockPackage>| {
// Require the bonus component every dat
{
let tpkg = pkgs[0]
Expand Down Expand Up @@ -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<MockPackage>| {
if date == "2016-02-01" {
let tpkg = pkgs[0]
.targets
Expand All @@ -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");
}
};

Expand All @@ -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());
},
);
}
Expand Down Expand Up @@ -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<MockPackage>| {
if date == "2016-02-01" {
let tpkg = pkgs[0]
.targets
Expand Down Expand Up @@ -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<MockPackage>| {
if date == "2016-02-01" {
let tpkg = pkgs[0]
.targets
Expand Down Expand Up @@ -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<MockPackage>| {
if date == "2016-02-01" {
let tpkg = pkgs[0]
.targets
Expand Down

0 comments on commit 0329ac7

Please sign in to comment.