@@ -46,9 +46,10 @@ pub(crate) struct FakeBuild {
4646 s3_build_log : Option < String > ,
4747 other_build_logs : HashMap < String , String > ,
4848 db_build_log : Option < String > ,
49- rustc_version : String ,
50- docsrs_version : String ,
49+ rustc_version : Option < String > ,
50+ docsrs_version : Option < String > ,
5151 build_status : BuildStatus ,
52+ errors : Option < String > ,
5253}
5354
5455const DEFAULT_CONTENT : & [ u8 ] =
@@ -547,14 +548,21 @@ impl FakeGithubStats {
547548impl FakeBuild {
548549 pub ( crate ) fn rustc_version ( self , rustc_version : impl Into < String > ) -> Self {
549550 Self {
550- rustc_version : rustc_version. into ( ) ,
551+ rustc_version : Some ( rustc_version. into ( ) ) ,
551552 ..self
552553 }
553554 }
554555
555556 pub ( crate ) fn docsrs_version ( self , docsrs_version : impl Into < String > ) -> Self {
556557 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 ( ) ) ,
558566 ..self
559567 }
560568 }
@@ -605,6 +613,18 @@ impl FakeBuild {
605613 }
606614 }
607615
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+
608628 async fn create (
609629 & self ,
610630 conn : & mut sqlx:: PgConnection ,
@@ -613,15 +633,26 @@ impl FakeBuild {
613633 default_target : & str ,
614634 ) -> Result < ( ) > {
615635 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+ }
625656
626657 if let Some ( db_build_log) = self . db_build_log . as_deref ( ) {
627658 sqlx:: query!(
@@ -653,14 +684,16 @@ impl FakeBuild {
653684}
654685
655686impl Default for FakeBuild {
687+ /// create a default fake _finished_ build
656688 fn default ( ) -> Self {
657689 Self {
658690 s3_build_log : Some ( "It works!" . into ( ) ) ,
659691 db_build_log : None ,
660692 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 ( ) ) ,
663695 build_status : BuildStatus :: Success ,
696+ errors : None ,
664697 }
665698 }
666699}
0 commit comments