Skip to content

Commit 4e91742

Browse files
Nemo157syphar
authored andcommitted
Add test that source archive with no cargo.toml is not an error
1 parent e69e8d7 commit 4e91742

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/test/fakes.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) struct FakeRelease<'a> {
3434
readme: Option<&'a str>,
3535
github_stats: Option<FakeGithubStats>,
3636
doc_coverage: Option<DocCoverage>,
37+
no_cargo_toml: bool,
3738
}
3839

3940
pub(crate) struct FakeBuild {
@@ -96,6 +97,7 @@ impl<'a> FakeRelease<'a> {
9697
github_stats: None,
9798
doc_coverage: None,
9899
archive_storage: false,
100+
no_cargo_toml: false,
99101
}
100102
}
101103

@@ -173,6 +175,11 @@ impl<'a> FakeRelease<'a> {
173175
self
174176
}
175177

178+
pub(crate) fn no_cargo_toml(mut self) -> Self {
179+
self.no_cargo_toml = true;
180+
self
181+
}
182+
176183
pub(crate) fn default_target(mut self, target: &'a str) -> Self {
177184
self = self.add_target(target);
178185
self.default_target = Some(target);
@@ -354,10 +361,11 @@ impl<'a> FakeRelease<'a> {
354361
let source_tmp = create_temp_dir();
355362
store_files_into(&self.source_files, source_tmp.path())?;
356363

357-
if !self
358-
.source_files
359-
.iter()
360-
.any(|&(path, _)| path == "Cargo.toml")
364+
if !self.no_cargo_toml
365+
&& !self
366+
.source_files
367+
.iter()
368+
.any(|&(path, _)| path == "Cargo.toml")
361369
{
362370
let MetadataPackage { name, version, .. } = &package;
363371
let content = format!(

src/web/crate_details.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,14 @@ mod tests {
11961196
.source_file("Cargo.toml", br#"package.readme = "MEREAD""#)
11971197
.create()?;
11981198

1199+
env.fake_release()
1200+
.name("dummy")
1201+
.version("0.5.0")
1202+
.readme_only_database("database readme")
1203+
.source_file("README.md", b"storage readme")
1204+
.no_cargo_toml()
1205+
.create()?;
1206+
11991207
let check_readme = |path, content| {
12001208
let resp = env.frontend().get(path).send().unwrap();
12011209
let body = String::from_utf8(resp.bytes().unwrap().to_vec()).unwrap();
@@ -1207,6 +1215,10 @@ mod tests {
12071215
check_readme("/crate/dummy/0.3.0", "storage readme");
12081216
check_readme("/crate/dummy/0.4.0", "storage meread");
12091217

1218+
let details = CrateDetails::new(&mut *env.db().conn(), "dummy", "0.5.0", "0.5.0", None)
1219+
.unwrap()
1220+
.unwrap();
1221+
assert!(matches!(details.fetch_readme(&env.storage()), Ok(None)));
12101222
Ok(())
12111223
});
12121224
}

0 commit comments

Comments
 (0)