@@ -46,9 +46,10 @@ pub(crate) struct FakeBuild {
46
46
s3_build_log : Option < String > ,
47
47
other_build_logs : HashMap < String , String > ,
48
48
db_build_log : Option < String > ,
49
- rustc_version : String ,
50
- docsrs_version : String ,
49
+ rustc_version : Option < String > ,
50
+ docsrs_version : Option < String > ,
51
51
build_status : BuildStatus ,
52
+ errors : Option < String > ,
52
53
}
53
54
54
55
const DEFAULT_CONTENT : & [ u8 ] =
@@ -547,14 +548,21 @@ impl FakeGithubStats {
547
548
impl FakeBuild {
548
549
pub ( crate ) fn rustc_version ( self , rustc_version : impl Into < String > ) -> Self {
549
550
Self {
550
- rustc_version : rustc_version. into ( ) ,
551
+ rustc_version : Some ( rustc_version. into ( ) ) ,
551
552
..self
552
553
}
553
554
}
554
555
555
556
pub ( crate ) fn docsrs_version ( self , docsrs_version : impl Into < String > ) -> Self {
556
557
Self {
557
- docsrs_version : docsrs_version. into ( ) ,
558
+ docsrs_version : Some ( docsrs_version. into ( ) ) ,
559
+ ..self
560
+ }
561
+ }
562
+
563
+ pub ( crate ) fn errors ( self , errors : impl Into < String > ) -> Self {
564
+ Self {
565
+ errors : Some ( errors. into ( ) ) ,
558
566
..self
559
567
}
560
568
}
@@ -605,6 +613,18 @@ impl FakeBuild {
605
613
}
606
614
}
607
615
616
+ pub ( crate ) fn empty_failed ( ) -> Self {
617
+ Self {
618
+ s3_build_log : None ,
619
+ db_build_log : None ,
620
+ other_build_logs : HashMap :: new ( ) ,
621
+ rustc_version : None ,
622
+ docsrs_version : None ,
623
+ build_status : BuildStatus :: Failure ,
624
+ errors : None ,
625
+ }
626
+ }
627
+
608
628
async fn create (
609
629
& self ,
610
630
conn : & mut sqlx:: PgConnection ,
@@ -613,15 +633,26 @@ impl FakeBuild {
613
633
default_target : & str ,
614
634
) -> Result < ( ) > {
615
635
let build_id = crate :: db:: initialize_build ( & mut * conn, release_id) . await ?;
616
- crate :: db:: finish_build (
617
- & mut * conn,
618
- build_id,
619
- & self . rustc_version ,
620
- & self . docsrs_version ,
621
- self . build_status ,
622
- None ,
623
- )
624
- . await ?;
636
+
637
+ if let ( Some ( rustc_version) , Some ( docsrs_version) ) =
638
+ ( & self . rustc_version , & self . docsrs_version )
639
+ {
640
+ crate :: db:: finish_build (
641
+ & mut * conn,
642
+ build_id,
643
+ rustc_version,
644
+ docsrs_version,
645
+ self . build_status ,
646
+ self . errors . as_deref ( ) ,
647
+ )
648
+ . await ?;
649
+ } else {
650
+ assert_eq ! ( self . build_status, BuildStatus :: Failure ) ;
651
+ assert ! ( self . rustc_version. is_none( ) ) ;
652
+ assert ! ( self . docsrs_version. is_none( ) ) ;
653
+ crate :: db:: update_build_with_error ( & mut * conn, build_id, self . errors . as_deref ( ) )
654
+ . await ?;
655
+ }
625
656
626
657
if let Some ( db_build_log) = self . db_build_log . as_deref ( ) {
627
658
sqlx:: query!(
@@ -653,14 +684,16 @@ impl FakeBuild {
653
684
}
654
685
655
686
impl Default for FakeBuild {
687
+ /// create a default fake _finished_ build
656
688
fn default ( ) -> Self {
657
689
Self {
658
690
s3_build_log : Some ( "It works!" . into ( ) ) ,
659
691
db_build_log : None ,
660
692
other_build_logs : HashMap :: new ( ) ,
661
- rustc_version : "rustc 2.0.0-nightly (000000000 1970-01-01)" . into ( ) ,
662
- docsrs_version : "docs.rs 1.0.0 (000000000 1970-01-01)" . into ( ) ,
693
+ rustc_version : Some ( "rustc 2.0.0-nightly (000000000 1970-01-01)" . into ( ) ) ,
694
+ docsrs_version : Some ( "docs.rs 1.0.0 (000000000 1970-01-01)" . into ( ) ) ,
663
695
build_status : BuildStatus :: Success ,
696
+ errors : None ,
664
697
}
665
698
}
666
699
}
0 commit comments