Skip to content

Commit a3465ed

Browse files
Nemo157syphar
authored andcommitted
Allow setting up fake release without builds
1 parent f428849 commit a3465ed

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
DELETE FROM compression_rels WHERE NOT EXISTS (
2+
SELECT 1
3+
FROM releases
4+
INNER JOIN builds ON builds.rid = releases.id
5+
WHERE releases.id = compression_rels.release
6+
);
7+
8+
DELETE FROM keyword_rels WHERE NOT EXISTS (
9+
SELECT 1
10+
FROM releases
11+
INNER JOIN builds ON builds.rid = releases.id
12+
WHERE releases.id = keyword_rels.rid
13+
);
14+
15+
DELETE FROM releases WHERE NOT EXISTS (
16+
SELECT *
17+
FROM builds
18+
WHERE builds.rid = releases.id
19+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- no up-migration, we only have a down-migration as validation

src/test/fakes.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) struct FakeRelease<'a> {
2222
storage: Arc<AsyncStorage>,
2323
runtime: Arc<Runtime>,
2424
package: MetadataPackage,
25-
builds: Vec<FakeBuild>,
25+
builds: Option<Vec<FakeBuild>>,
2626
/// name, content
2727
source_files: Vec<(&'a str, &'a [u8])>,
2828
/// name, content
@@ -90,7 +90,7 @@ impl<'a> FakeRelease<'a> {
9090
.cloned()
9191
.collect::<HashMap<String, Vec<String>>>(),
9292
},
93-
builds: vec![],
93+
builds: None,
9494
source_files: Vec::new(),
9595
rustdoc_files: Vec::new(),
9696
doc_targets: Vec::new(),
@@ -147,20 +147,31 @@ impl<'a> FakeRelease<'a> {
147147
// TODO: How should `has_docs` actually be handled?
148148
pub(crate) fn build_result_failed(self) -> Self {
149149
assert!(
150-
self.builds.is_empty(),
150+
self.builds.is_none(),
151151
"cannot use custom builds with build_result_failed"
152152
);
153153
Self {
154154
has_docs: false,
155-
builds: vec![FakeBuild::default().successful(false)],
155+
builds: Some(vec![FakeBuild::default().successful(false)]),
156156
..self
157157
}
158158
}
159159

160160
pub(crate) fn builds(self, builds: Vec<FakeBuild>) -> Self {
161-
assert!(self.builds.is_empty());
161+
assert!(self.builds.is_none());
162162
assert!(!builds.is_empty());
163-
Self { builds, ..self }
163+
Self {
164+
builds: Some(builds),
165+
..self
166+
}
167+
}
168+
169+
pub(crate) fn no_builds(self) -> Self {
170+
assert!(self.builds.is_none());
171+
Self {
172+
builds: Some(vec![]),
173+
..self
174+
}
164175
}
165176

166177
pub(crate) fn yanked(mut self, new: bool) -> Self {
@@ -281,7 +292,7 @@ impl<'a> FakeRelease<'a> {
281292
}
282293

283294
/// Returns the release_id
284-
pub(crate) async fn create_async(mut self) -> Result<i32> {
295+
pub(crate) async fn create_async(self) -> Result<i32> {
285296
use std::fs;
286297
use std::path::Path;
287298

@@ -417,12 +428,9 @@ impl<'a> FakeRelease<'a> {
417428
debug!("added source files {}", source_meta);
418429

419430
// If the test didn't add custom builds, inject a default one
420-
if self.builds.is_empty() {
421-
self.builds.push(FakeBuild::default());
422-
}
423-
let last_build_result = &self.builds.last().unwrap().result;
431+
let builds = self.builds.unwrap_or_else(|| vec![FakeBuild::default()]);
424432

425-
if last_build_result.successful {
433+
if builds.last().map(|b| b.result.successful).unwrap_or(false) {
426434
let index = [&package.name, "index.html"].join("/");
427435
if package.is_library() && !rustdoc_files.iter().any(|(path, _)| path == &index) {
428436
rustdoc_files.push((&index, DEFAULT_CONTENT));
@@ -494,7 +502,7 @@ impl<'a> FakeRelease<'a> {
494502
&self.registry_crate_data,
495503
)
496504
.await?;
497-
for build in &self.builds {
505+
for build in builds {
498506
build
499507
.create(&mut async_conn, &storage, release_id, default_target)
500508
.await?;

0 commit comments

Comments
 (0)