Skip to content

Commit 4d8822e

Browse files
committed
WIP
1 parent f26ed7b commit 4d8822e

File tree

2 files changed

+84
-15
lines changed

2 files changed

+84
-15
lines changed

src/test/fakes.rs

+48-15
Original file line numberDiff line numberDiff line change
@@ -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

5455
const DEFAULT_CONTENT: &[u8] =
@@ -547,14 +548,21 @@ impl FakeGithubStats {
547548
impl 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

655686
impl 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
}

src/web/build_details.rs

+36
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,42 @@ mod tests {
149149
.collect()
150150
}
151151

152+
#[test]
153+
fn test_partial_build_result() {
154+
wrapper(|env| {
155+
let release_id = env
156+
.fake_release()
157+
.name("foo")
158+
.version("0.1.0")
159+
.builds(vec![FakeBuild::empty_failed().errors("some random error")])
160+
.create()?;
161+
162+
let build_id = env.runtime().block_on(async {
163+
let mut conn = env.async_db().await.async_conn().await;
164+
165+
sqlx::query_scalar!("SELECT id FROM builds WHERE rid = $1", release_id)
166+
.fetch_one(&mut *conn)
167+
.await
168+
})?;
169+
170+
let page = kuchikiki::parse_html().one(
171+
env.frontend()
172+
.get(&format!("/crate/foo/0.1.0/builds/{build_id}"))
173+
.send()?
174+
.error_for_status()?
175+
.text()?,
176+
);
177+
178+
let info_text = dbg!(page.select("pre").unwrap().next())
179+
.unwrap()
180+
.text_contents();
181+
182+
assert!(info_text.contains("some random error"));
183+
184+
Ok(())
185+
});
186+
}
187+
152188
#[test]
153189
fn db_build_logs() {
154190
wrapper(|env| {

0 commit comments

Comments
 (0)