Skip to content

Commit bd5ac16

Browse files
committed
Update tests
1 parent 58db76a commit bd5ac16

File tree

1 file changed

+62
-14
lines changed

1 file changed

+62
-14
lines changed

src/rustup-dist/tests/dist.rs

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,11 @@ fn upgrade() {
645645
}
646646

647647
#[test]
648-
fn force_update() {
649-
// On day 1 install the 'bonus' component, on day 2 its no longer a component
648+
fn unavailable_component() {
649+
// On day 2 the bonus component is no longer available
650650
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
651-
if date == "2016-02-01" {
651+
// Require the bonus component every dat
652+
{
652653
let tpkg = pkgs[0].targets
653654
.iter_mut()
654655
.find(|p| p.target == "x86_64-apple-darwin")
@@ -658,6 +659,17 @@ fn force_update() {
658659
target: "x86_64-apple-darwin".to_string(),
659660
});
660661
}
662+
663+
// Mark the bonus package as unavailable in 2016-02-02
664+
if date == "2016-02-02" {
665+
let bonus_pkg = pkgs.iter_mut()
666+
.find(|p| p.name == "bonus")
667+
.unwrap();
668+
669+
for target in &mut bonus_pkg.targets {
670+
target.available = false;
671+
}
672+
}
661673
};
662674

663675
setup(
@@ -677,18 +689,54 @@ fn force_update() {
677689
ErrorKind::RequestedComponentsUnavailable(..) => {}
678690
_ => panic!(),
679691
}
680-
// Force update without bonus, should succeed, but bonus binary will be missing.
681-
update_from_dist_(
682-
url,
683-
toolchain,
684-
prefix,
685-
&[],
686-
&[],
687-
download_cfg,
688-
temp_cfg,
689-
true,
690-
).unwrap();
692+
},
693+
);
694+
}
695+
696+
#[test]
697+
fn removed_component() {
698+
// On day 1 install the 'bonus' component, on day 2 its no longer a component
699+
let edit = &|date: &str, pkgs: &mut [MockPackage]| {
700+
if date == "2016-02-01" {
701+
let tpkg = pkgs[0].targets
702+
.iter_mut()
703+
.find(|p| p.target == "x86_64-apple-darwin")
704+
.unwrap();
705+
tpkg.components.push(MockComponent {
706+
name: "bonus".to_string(),
707+
target: "x86_64-apple-darwin".to_string(),
708+
});
709+
}
710+
};
711+
712+
setup(
713+
Some(edit),
714+
false,
715+
&|url, toolchain, prefix, download_cfg, temp_cfg| {
716+
let received_notification = Arc::new(Cell::new(false));
717+
718+
let download_cfg = DownloadCfg {
719+
dist_root: download_cfg.dist_root,
720+
temp_cfg: download_cfg.temp_cfg,
721+
download_dir: download_cfg.download_dir,
722+
notify_handler: &|n| {
723+
if let Notification::ComponentUnavailable("bonus", Some(_)) = n {
724+
received_notification.set(true);
725+
}
726+
},
727+
};
728+
729+
change_channel_date(url, "nightly", "2016-02-01");
730+
// Update with bonus.
731+
update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap();
732+
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
733+
change_channel_date(url, "nightly", "2016-02-02");
734+
735+
// Update without bonus, should emit a notify and remove the bonus component
736+
update_from_dist(url, toolchain, prefix, &[], &[], &download_cfg, temp_cfg).unwrap();
691737
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
738+
739+
assert!(received_notification.get());
692740
},
693741
);
694742
}

0 commit comments

Comments
 (0)