@@ -29,12 +29,14 @@ use rustup_mock::clitools::{self, Config, Scenario,
29
29
expect_stderr_ok,
30
30
expect_err, expect_err_ex,
31
31
this_host_triple} ;
32
- use rustup_mock:: dist:: { create_hash , calc_hash} ;
32
+ use rustup_mock:: dist:: { calc_hash} ;
33
33
use rustup_mock:: { get_path, restore_path} ;
34
- use rustup_utils:: raw;
34
+ use rustup_utils:: { utils , raw} ;
35
35
36
36
macro_rules! for_host { ( $s: expr) => ( & format!( $s, this_host_triple( ) ) ) }
37
37
38
+ const TEST_VERSION : & ' static str = "1.1.1" ;
39
+
38
40
pub fn setup ( f : & Fn ( & Config ) ) {
39
41
clitools:: setup ( Scenario :: SimpleV2 , & |config| {
40
42
// Lock protects environment variables
@@ -60,16 +62,15 @@ pub fn update_setup(f: &Fn(&Config, &Path)) {
60
62
let ref self_dist = self_dist_tmp. path ( ) ;
61
63
62
64
let ref trip = this_host_triple ( ) ;
63
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
65
+ let ref dist_dir = self_dist. join ( & format ! ( "archive/{}/{}" , TEST_VERSION , trip) ) ;
64
66
let ref dist_exe = dist_dir. join ( & format ! ( "rustup-init{}" , EXE_SUFFIX ) ) ;
65
- let ref dist_hash = dist_dir. join ( & format ! ( "rustup-init{}.sha256" , EXE_SUFFIX ) ) ;
66
67
let ref rustup_bin = config. exedir . join ( & format ! ( "rustup-init{}" , EXE_SUFFIX ) ) ;
67
68
68
69
fs:: create_dir_all ( dist_dir) . unwrap ( ) ;
70
+ output_release_file ( self_dist, "1" , TEST_VERSION ) ;
69
71
fs:: copy ( rustup_bin, dist_exe) . unwrap ( ) ;
70
72
// Modify the exe so it hashes different
71
73
raw:: append_file ( dist_exe, "" ) . unwrap ( ) ;
72
- create_hash ( dist_exe, dist_hash) ;
73
74
74
75
let ref root_url = format ! ( "file://{}" , self_dist. display( ) ) ;
75
76
env:: set_var ( "RUSTUP_UPDATE_ROOT" , root_url) ;
@@ -78,6 +79,15 @@ pub fn update_setup(f: &Fn(&Config, &Path)) {
78
79
} ) ;
79
80
}
80
81
82
+ fn output_release_file ( dist_dir : & Path , schema : & str , version : & str ) {
83
+ let contents = format ! ( r#"
84
+ schema-version = "{}"
85
+ version = "{}"
86
+ "# , schema, version) ;
87
+ let file = dist_dir. join ( "release-stable.toml" ) ;
88
+ utils:: write_file ( "release" , & file, & contents) . unwrap ( ) ;
89
+ }
90
+
81
91
#[ test]
82
92
fn install_bins_to_cargo_home ( ) {
83
93
setup ( & |config| {
@@ -503,88 +513,13 @@ fn update_but_delete_existing_updater_first() {
503
513
} ) ;
504
514
}
505
515
506
- #[ test]
507
- fn update_no_change ( ) {
508
- update_setup ( & |config, self_dist| {
509
- expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
510
-
511
- let ref trip = this_host_triple ( ) ;
512
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
513
- let ref dist_exe = dist_dir. join ( & format ! ( "rustup-init{}" , EXE_SUFFIX ) ) ;
514
- let ref dist_hash = dist_dir. join ( & format ! ( "rustup-init{}.sha256" , EXE_SUFFIX ) ) ;
515
- let ref rustup_bin = config. exedir . join ( & format ! ( "rustup{}" , EXE_SUFFIX ) ) ;
516
- fs:: copy ( rustup_bin, dist_exe) . unwrap ( ) ;
517
- create_hash ( dist_exe, dist_hash) ;
518
-
519
- expect_ok_ex ( config, & [ "rustup" , "self" , "update" ] ,
520
- r"" ,
521
- r"info: checking for self-updates
522
- " ) ;
523
-
524
- } ) ;
525
- }
526
-
527
- #[ test]
528
- #[ ignore] // Workaround for #346
529
- fn update_bad_hash ( ) {
530
- update_setup ( & |config, self_dist| {
531
- expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
532
-
533
- let ref trip = this_host_triple ( ) ;
534
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
535
- let ref dist_hash = dist_dir. join ( & format ! ( "rustup-init{}.sha256" , EXE_SUFFIX ) ) ;
536
-
537
- let ref some_other_file = config. distdir . join ( "dist/channel-rust-nightly.toml" ) ;
538
-
539
- create_hash ( some_other_file, dist_hash) ;
540
-
541
- expect_err ( config, & [ "rustup" , "self" , "update" ] ,
542
- "checksum failed" ) ;
543
- } ) ;
544
- }
545
-
546
- // Workaround for #346
547
- #[ test]
548
- fn update_hash_drift ( ) {
549
- update_setup ( & |config, self_dist| {
550
- expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
551
-
552
- let ref trip = this_host_triple ( ) ;
553
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
554
- let ref dist_hash = dist_dir. join ( & format ! ( "rustup-init{}.sha256" , EXE_SUFFIX ) ) ;
555
-
556
- let ref some_other_file = config. distdir . join ( "dist/channel-rust-nightly.toml" ) ;
557
-
558
- create_hash ( some_other_file, dist_hash) ;
559
-
560
- expect_stderr_ok ( config, & [ "rustup" , "self" , "update" ] ,
561
- "update not yet available" ) ;
562
- } ) ;
563
- }
564
-
565
- #[ test]
566
- fn update_hash_file_404 ( ) {
567
- update_setup ( & |config, self_dist| {
568
- expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
569
-
570
- let ref trip = this_host_triple ( ) ;
571
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
572
- let ref dist_hash = dist_dir. join ( & format ! ( "rustup-init{}.sha256" , EXE_SUFFIX ) ) ;
573
-
574
- fs:: remove_file ( dist_hash) . unwrap ( ) ;
575
-
576
- expect_err ( config, & [ "rustup" , "self" , "update" ] ,
577
- "could not download file" ) ;
578
- } ) ;
579
- }
580
-
581
516
#[ test]
582
517
fn update_download_404 ( ) {
583
518
update_setup ( & |config, self_dist| {
584
519
expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
585
520
586
521
let ref trip = this_host_triple ( ) ;
587
- let ref dist_dir = self_dist. join ( & format ! ( "{}" , trip) ) ;
522
+ let ref dist_dir = self_dist. join ( & format ! ( "archive/{}/{}" , TEST_VERSION , trip) ) ;
588
523
let ref dist_exe = dist_dir. join ( & format ! ( "rustup-init{}" , EXE_SUFFIX ) ) ;
589
524
590
525
fs:: remove_file ( dist_exe) . unwrap ( ) ;
@@ -632,6 +567,29 @@ fn update_updates_rustup_bin() {
632
567
} ) ;
633
568
}
634
569
570
+ #[ test]
571
+ fn update_bad_schema ( ) {
572
+ update_setup ( & |config, self_dist| {
573
+ expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
574
+ output_release_file ( dist_dir, "17" , "1.1.1" ) ;
575
+ expect_err ( config, & [ "rustup" , "self" , "update" ] ,
576
+ "unknown schema version" ) ;
577
+ } ) ;
578
+ }
579
+
580
+ #[ test]
581
+ fn update_no_change ( ) {
582
+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
583
+ update_setup ( & |config, self_dist| {
584
+ expect_ok ( config, & [ "rustup-init" , "-y" ] ) ;
585
+ output_release_file ( dist_dir, "1" , version) ;
586
+ expect_ok_ex ( config, & [ "rustup" , "self" , "update" ] ,
587
+ r"" ,
588
+ r"info: checking for self-updates
589
+ " ) ;
590
+ } ) ;
591
+ }
592
+
635
593
#[ test]
636
594
fn rustup_self_updates ( ) {
637
595
update_setup ( & |config, _| {
0 commit comments