Skip to content

Commit 679d9d6

Browse files
committed
add rustdoc json to test fakes, update delete_version to also delete json
1 parent 7d484e9 commit 679d9d6

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

src/db/delete.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::{CrateId, update_latest_version_id};
1111

1212
/// List of directories in docs.rs's underlying storage (either the database or S3) containing a
1313
/// subdirectory named after the crate. Those subdirectories will be deleted.
14-
static LIBRARY_STORAGE_PATHS_TO_DELETE: &[&str] = &["rustdoc", "sources"];
14+
static LIBRARY_STORAGE_PATHS_TO_DELETE: &[&str] = &["rustdoc", "rustdoc-json", "sources"];
1515
static OTHER_STORAGE_PATHS_TO_DELETE: &[&str] = &["sources"];
1616

1717
#[derive(Debug, thiserror::Error)]
@@ -222,6 +222,7 @@ mod tests {
222222
use super::*;
223223
use crate::db::ReleaseId;
224224
use crate::registry_api::{CrateOwner, OwnerKind};
225+
use crate::storage::rustdoc_json_path;
225226
use crate::test::{async_wrapper, fake_release_that_failed_before_build};
226227
use test_case::test_case;
227228

@@ -426,6 +427,17 @@ mod tests {
426427
.rustdoc_file_exists("a", "1.0.0", None, "a/index.html", archive_storage)
427428
.await?
428429
);
430+
assert!(
431+
env.async_storage()
432+
.await
433+
.exists(&rustdoc_json_path(
434+
"a",
435+
"1.0.0",
436+
"x86_64-unknown-linux-gnu",
437+
crate::storage::RustdocJsonFormatVersion::Latest
438+
))
439+
.await?
440+
);
429441
let crate_id = sqlx::query_scalar!(
430442
r#"SELECT crate_id as "crate_id: CrateId" FROM releases WHERE id = $1"#,
431443
v1.0
@@ -457,6 +469,17 @@ mod tests {
457469
.rustdoc_file_exists("a", "2.0.0", None, "a/index.html", archive_storage)
458470
.await?
459471
);
472+
assert!(
473+
env.async_storage()
474+
.await
475+
.exists(&rustdoc_json_path(
476+
"a",
477+
"2.0.0",
478+
"x86_64-unknown-linux-gnu",
479+
crate::storage::RustdocJsonFormatVersion::Latest
480+
))
481+
.await?
482+
);
460483
assert_eq!(
461484
owners(&mut conn, crate_id).await?,
462485
vec!["Peter Rabbit".to_string()]
@@ -494,13 +517,36 @@ mod tests {
494517
.await?
495518
);
496519
}
520+
assert!(
521+
!env.async_storage()
522+
.await
523+
.exists(&rustdoc_json_path(
524+
"a",
525+
"1.0.0",
526+
"x86_64-unknown-linux-gnu",
527+
crate::storage::RustdocJsonFormatVersion::Latest
528+
))
529+
.await?
530+
);
531+
497532
assert!(release_exists(&mut conn, v2).await?);
498533
assert!(
499534
env.async_storage()
500535
.await
501536
.rustdoc_file_exists("a", "2.0.0", None, "a/index.html", archive_storage)
502537
.await?
503538
);
539+
assert!(
540+
env.async_storage()
541+
.await
542+
.exists(&rustdoc_json_path(
543+
"a",
544+
"2.0.0",
545+
"x86_64-unknown-linux-gnu",
546+
crate::storage::RustdocJsonFormatVersion::Latest
547+
))
548+
.await?
549+
);
504550
assert_eq!(
505551
owners(&mut conn, crate_id).await?,
506552
vec!["Peter Rabbit".to_string()]

src/storage/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ pub(crate) fn rustdoc_json_path(
831831
format_version: RustdocJsonFormatVersion,
832832
) -> String {
833833
format!(
834-
"/rustdoc-json/{name}/{version}/{target}/{name}_{version}_{target}_{format_version}.json.zst"
834+
"rustdoc-json/{name}/{version}/{target}/{name}_{version}_{target}_{format_version}.json.zst"
835835
)
836836
}
837837

src/test/fakes.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::docbuilder::DocCoverage;
99
use crate::error::Result;
1010
use crate::registry_api::{CrateData, CrateOwner, ReleaseData};
1111
use crate::storage::{
12-
AsyncStorage, CompressionAlgorithm, rustdoc_archive_path, source_archive_path,
12+
AsyncStorage, CompressionAlgorithm, RustdocJsonFormatVersion, rustdoc_archive_path,
13+
rustdoc_json_path, source_archive_path,
1314
};
1415
use crate::utils::{Dependency, MetadataPackage, Target};
1516
use anyhow::{Context, bail};
@@ -512,10 +513,38 @@ impl<'a> FakeRelease<'a> {
512513
}
513514
store_files_into(&self.source_files, crate_dir)?;
514515

516+
let default_target = self.default_target.unwrap_or("x86_64-unknown-linux-gnu");
517+
518+
{
519+
let mut targets = self.doc_targets.clone();
520+
if !targets.contains(&default_target.to_owned()) {
521+
targets.push(default_target.to_owned());
522+
}
523+
for target in &targets {
524+
for format_version in [
525+
RustdocJsonFormatVersion::Version(42),
526+
RustdocJsonFormatVersion::Latest,
527+
] {
528+
storage
529+
.store_one(
530+
&rustdoc_json_path(
531+
&package.name,
532+
&package.version,
533+
&target,
534+
format_version,
535+
),
536+
serde_json::to_vec(&serde_json::json!({
537+
"format_version": 42
538+
}))?,
539+
)
540+
.await?;
541+
}
542+
}
543+
}
544+
515545
// Many tests rely on the default-target being linux, so it should not
516546
// be set to docsrs_metadata::HOST_TARGET, because then tests fail on all
517547
// non-linux platforms.
518-
let default_target = self.default_target.unwrap_or("x86_64-unknown-linux-gnu");
519548
let mut async_conn = db.async_conn().await;
520549
let crate_id = initialize_crate(&mut async_conn, &package.name).await?;
521550
let release_id = initialize_release(&mut async_conn, crate_id, &package.version).await?;

0 commit comments

Comments
 (0)