Skip to content

Commit

Permalink
Add test for xz tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
ranma42 committed May 19, 2017
1 parent 4704e96 commit 7232a56
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 54 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 43 additions & 33 deletions src/rustup-dist/tests/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn mock_dist_server_smoke_test() {
let tempdir = TempDir::new("multirust").unwrap();
let path = tempdir.path();

create_mock_dist_server(&path, None).write(&[ManifestVersion::V2]);
create_mock_dist_server(&path, None).write(&[ManifestVersion::V2], false);

assert!(utils::path_exists(path.join("dist/2016-02-01/rustc-nightly-x86_64-apple-darwin.tar.gz")));
assert!(utils::path_exists(path.join("dist/2016-02-01/rustc-nightly-i686-apple-darwin.tar.gz")));
Expand Down Expand Up @@ -308,10 +308,10 @@ fn uninstall(toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp:
Ok(())
}

fn setup(edit: Option<&Fn(&str, &mut MockPackage)>,
fn setup(edit: Option<&Fn(&str, &mut MockPackage)>, enable_xz: bool,
f: &Fn(&Url, &ToolchainDesc, &InstallPrefix, &dist::DownloadCfg, &temp::Cfg)) {
let dist_tempdir = TempDir::new("multirust").unwrap();
create_mock_dist_server(dist_tempdir.path(), edit).write(&[ManifestVersion::V2]);
create_mock_dist_server(dist_tempdir.path(), edit).write(&[ManifestVersion::V2], enable_xz);

let prefix_tempdir = TempDir::new("multirust").unwrap();

Expand All @@ -335,7 +335,17 @@ fn setup(edit: Option<&Fn(&str, &mut MockPackage)>,

#[test]
fn initial_install() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

assert!(utils::path_exists(&prefix.path().join("bin/rustc")));
assert!(utils::path_exists(&prefix.path().join("lib/libstd.rlib")));
});
}

#[test]
fn initial_install_xz() {
setup(None, true, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

assert!(utils::path_exists(&prefix.path().join("bin/rustc")));
Expand All @@ -345,7 +355,7 @@ fn initial_install() {

#[test]
fn test_uninstall() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
uninstall(toolchain, prefix, temp_cfg, &|_| ()).unwrap();

Expand All @@ -356,7 +366,7 @@ fn test_uninstall() {

#[test]
fn uninstall_removes_config_file() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
assert!(utils::path_exists(&prefix.manifest_file("multirust-config.toml")));
uninstall(toolchain, prefix, temp_cfg, &|_| ()).unwrap();
Expand All @@ -366,7 +376,7 @@ fn uninstall_removes_config_file() {

#[test]
fn upgrade() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
assert_eq!("2016-02-01", utils_raw::read_file(&prefix.path().join("bin/rustc")).unwrap());
Expand All @@ -388,7 +398,7 @@ fn update_removes_components_that_dont_exist() {
});
}
};
setup(Some(edit), &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
Expand All @@ -400,7 +410,7 @@ fn update_removes_components_that_dont_exist() {

#[test]
fn update_preserves_extensions() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-std".to_string(), target: Some(TargetTriple::from_str("i686-apple-darwin"))
Expand Down Expand Up @@ -442,7 +452,7 @@ fn update_preserves_extensions_that_became_components() {
});
}
};
setup(Some(edit), &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "bonus".to_string(), target: Some(TargetTriple::from_str("x86_64-apple-darwin"))
Expand Down Expand Up @@ -478,7 +488,7 @@ fn update_preserves_components_that_became_extensions() {
});
}
};
setup(Some(edit), &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
Expand All @@ -490,7 +500,7 @@ fn update_preserves_components_that_became_extensions() {

#[test]
fn update_makes_no_changes_for_identical_manifest() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let status = update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
assert_eq!(status, UpdateStatus::Changed);
let status = update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
Expand All @@ -500,7 +510,7 @@ fn update_makes_no_changes_for_identical_manifest() {

#[test]
fn add_extensions_for_initial_install() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-std".to_string(), target: Some(TargetTriple::from_str("i686-apple-darwin"))
Expand All @@ -518,7 +528,7 @@ fn add_extensions_for_initial_install() {

#[test]
fn add_extensions_for_same_manifest() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

let ref adds = vec![
Expand All @@ -539,7 +549,7 @@ fn add_extensions_for_same_manifest() {

#[test]
fn add_extensions_for_upgrade() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");

update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
Expand All @@ -565,7 +575,7 @@ fn add_extensions_for_upgrade() {
#[test]
#[should_panic]
fn add_extension_not_in_manifest() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-bogus".to_string(), target: Some(TargetTriple::from_str("i686-apple-darwin"))
Expand All @@ -579,7 +589,7 @@ fn add_extension_not_in_manifest() {
#[test]
#[should_panic]
fn add_extension_that_is_required_component() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rustc".to_string(), target: Some(TargetTriple::from_str("x86_64-apple-darwin"))
Expand All @@ -602,7 +612,7 @@ fn add_extensions_for_same_manifest_when_extension_already_installed() {

#[test]
fn add_extensions_does_not_remove_other_components() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

let ref adds = vec![
Expand All @@ -621,7 +631,7 @@ fn add_extensions_does_not_remove_other_components() {
#[test]
#[should_panic]
fn remove_extensions_for_initial_install() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref removes = vec![
Component {
pkg: "rustc".to_string(), target: Some(TargetTriple::from_str("x86_64-apple-darwin"))
Expand All @@ -634,7 +644,7 @@ fn remove_extensions_for_initial_install() {

#[test]
fn remove_extensions_for_same_manifest() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-std".to_string(), target: Some(TargetTriple::from_str("i686-apple-darwin"))
Expand All @@ -661,7 +671,7 @@ fn remove_extensions_for_same_manifest() {

#[test]
fn remove_extensions_for_upgrade() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");

let ref adds = vec![
Expand Down Expand Up @@ -693,7 +703,7 @@ fn remove_extensions_for_upgrade() {
#[test]
#[should_panic]
fn remove_extension_not_in_manifest() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");

update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();
Expand Down Expand Up @@ -725,7 +735,7 @@ fn remove_extension_not_in_manifest_but_is_already_installed() {
});
}
};
setup(Some(edit), &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");

let ref adds = vec![
Expand All @@ -750,7 +760,7 @@ fn remove_extension_not_in_manifest_but_is_already_installed() {
#[test]
#[should_panic]
fn remove_extension_that_is_required_component() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

let ref removes = vec![
Expand All @@ -766,7 +776,7 @@ fn remove_extension_that_is_required_component() {
#[test]
#[should_panic]
fn remove_extension_not_installed() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

let ref removes = vec![
Expand All @@ -786,7 +796,7 @@ fn remove_extensions_for_same_manifest_does_not_reinstall_other_components() {

#[test]
fn remove_extensions_does_not_remove_other_components() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-std".to_string(), target: Some(TargetTriple::from_str("i686-apple-darwin"))
Expand All @@ -809,7 +819,7 @@ fn remove_extensions_does_not_remove_other_components() {

#[test]
fn add_and_remove_for_upgrade() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
change_channel_date(url, "nightly", "2016-02-01");

let ref adds = vec![
Expand Down Expand Up @@ -843,7 +853,7 @@ fn add_and_remove_for_upgrade() {

#[test]
fn add_and_remove() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let ref adds = vec![
Component {
pkg: "rust-std".to_string(), target: Some(TargetTriple::from_str("i686-unknown-linux-gnu"))
Expand Down Expand Up @@ -874,7 +884,7 @@ fn add_and_remove() {
#[test]
#[should_panic]
fn add_and_remove_same_component() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, &|_| ()).unwrap();

let ref adds = vec![
Expand All @@ -895,7 +905,7 @@ fn add_and_remove_same_component() {

#[test]
fn bad_component_hash() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let path = url.to_file_path().unwrap();
let path = path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz");
utils_raw::write_file(&path, "bogus").unwrap();
Expand All @@ -911,7 +921,7 @@ fn bad_component_hash() {

#[test]
fn unable_to_download_component() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
let path = url.to_file_path().unwrap();
let path = path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz");
fs::remove_file(&path).unwrap();
Expand All @@ -938,7 +948,7 @@ fn allow_installation(prefix: &InstallPrefix) {

#[test]
fn reuse_downloaded_file() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {

prevent_installation(prefix);

Expand All @@ -959,7 +969,7 @@ fn reuse_downloaded_file() {

#[test]
fn checks_files_hashes_before_reuse() {
setup(None, &|url, toolchain, prefix, download_cfg, temp_cfg| {
setup(None, false, &|url, toolchain, prefix, download_cfg, temp_cfg| {

let path = url.to_file_path().unwrap();
let target_hash = utils::read_file("target hash", &path.join("dist/2016-02-02/rustc-nightly-x86_64-apple-darwin.tar.gz.sha256")).unwrap()[.. 64].to_owned();
Expand Down
1 change: 1 addition & 0 deletions src/rustup-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ scopeguard = "0.1.2"
lazy_static = "0.1.15"
walkdir = "0.1.5"
flate2 = "0.2.9"
xz2 = "0.1.3"
tempdir = "0.3.4"
itertools = "0.4.1"
tar = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
MockDistServer {
path: path.to_owned(),
channels: chans,
}.write(vs);
}.write(vs, true);

// Also create the manifests for stable releases by version
if s == Scenario::Full || s == Scenario::ArchivesV1 || s == Scenario::ArchivesV2 {
Expand Down
Loading

0 comments on commit 7232a56

Please sign in to comment.