Skip to content

Commit

Permalink
Add test that source archive with no cargo.toml is not an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Aug 25, 2023
1 parent 0b1acff commit fb48d5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) struct FakeRelease<'a> {
readme: Option<&'a str>,
github_stats: Option<FakeGithubStats>,
doc_coverage: Option<DocCoverage>,
no_cargo_toml: bool,
}

pub(crate) struct FakeBuild {
Expand Down Expand Up @@ -96,6 +97,7 @@ impl<'a> FakeRelease<'a> {
github_stats: None,
doc_coverage: None,
archive_storage: false,
no_cargo_toml: false,
}
}

Expand Down Expand Up @@ -173,6 +175,11 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn no_cargo_toml(mut self) -> Self {
self.no_cargo_toml = true;
self
}

pub(crate) fn default_target(mut self, target: &'a str) -> Self {
self = self.add_target(target);
self.default_target = Some(target);
Expand Down Expand Up @@ -354,10 +361,11 @@ impl<'a> FakeRelease<'a> {
let source_tmp = create_temp_dir();
store_files_into(&self.source_files, source_tmp.path())?;

if !self
.source_files
.iter()
.any(|&(path, _)| path == "Cargo.toml")
if !self.no_cargo_toml
&& !self
.source_files
.iter()
.any(|&(path, _)| path == "Cargo.toml")
{
let MetadataPackage { name, version, .. } = &package;
let content = format!(
Expand Down
12 changes: 12 additions & 0 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,14 @@ mod tests {
.source_file("Cargo.toml", br#"package.readme = "MEREAD""#)
.create()?;

env.fake_release()
.name("dummy")
.version("0.5.0")
.readme_only_database("database readme")
.source_file("README.md", b"storage readme")
.no_cargo_toml()
.create()?;

let check_readme = |path, content| {
let resp = env.frontend().get(path).send().unwrap();
let body = String::from_utf8(resp.bytes().unwrap().to_vec()).unwrap();
Expand All @@ -1207,6 +1215,10 @@ mod tests {
check_readme("/crate/dummy/0.3.0", "storage readme");
check_readme("/crate/dummy/0.4.0", "storage meread");

let details = CrateDetails::new(&mut *env.db().conn(), "dummy", "0.5.0", "0.5.0", None)
.unwrap()
.unwrap();
assert!(matches!(details.fetch_readme(&*env.storage()), Ok(None)));
Ok(())
});
}
Expand Down

0 comments on commit fb48d5b

Please sign in to comment.