Skip to content

Commit ab87ead

Browse files
committed
tests/builders/version: Remove sync build() fns
1 parent a74e6df commit ab87ead

File tree

5 files changed

+8
-72
lines changed

5 files changed

+8
-72
lines changed

src/tests/builders/krate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a> CrateBuilder<'a> {
141141
let mut last_version_id = 0;
142142
for version_builder in self.versions {
143143
last_version_id = version_builder
144-
.async_build(krate.id, self.owner_id, connection)
144+
.build(krate.id, self.owner_id, connection)
145145
.await?
146146
.id;
147147
}

src/tests/builders/version.rs

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl VersionBuilder {
9191
self
9292
}
9393

94-
pub async fn async_build(
94+
pub async fn build(
9595
self,
9696
crate_id: i32,
9797
published_by: i32,
@@ -142,83 +142,19 @@ impl VersionBuilder {
142142
Ok(vers)
143143
}
144144

145-
pub fn build(
146-
self,
147-
crate_id: i32,
148-
published_by: i32,
149-
connection: &mut PgConnection,
150-
) -> AppResult<Version> {
151-
use diesel::{insert_into, RunQueryDsl};
152-
153-
let version = self.num.to_string();
154-
155-
let new_version = NewVersion::builder(crate_id, &version)
156-
.features(serde_json::to_value(&self.features)?)
157-
.maybe_license(self.license.as_deref())
158-
.size(self.size)
159-
.published_by(published_by)
160-
.checksum(&self.checksum)
161-
.maybe_links(self.links.as_deref())
162-
.maybe_rust_version(self.rust_version.as_deref())
163-
.yanked(self.yanked)
164-
.maybe_created_at(self.created_at.as_ref())
165-
.build();
166-
167-
let vers = new_version.save(connection, "[email protected]")?;
168-
169-
let new_deps = self
170-
.dependencies
171-
.into_iter()
172-
.map(|(crate_id, target)| {
173-
(
174-
dependencies::version_id.eq(vers.id),
175-
dependencies::req.eq(">= 0"),
176-
dependencies::crate_id.eq(crate_id),
177-
dependencies::target.eq(target),
178-
dependencies::optional.eq(false),
179-
dependencies::default_features.eq(false),
180-
dependencies::features.eq(Vec::<String>::new()),
181-
)
182-
})
183-
.collect::<Vec<_>>();
184-
insert_into(dependencies::table)
185-
.values(&new_deps)
186-
.execute(connection)?;
187-
188-
Ok(vers)
189-
}
190-
191145
/// Consumes the builder and creates the version record in the database.
192146
///
193147
/// # Panics
194148
///
195149
/// Panics (and fails the test) if any part of inserting the version record fails.
196-
pub async fn async_expect_build(
150+
pub async fn expect_build(
197151
self,
198152
crate_id: i32,
199153
published_by: i32,
200154
connection: &mut AsyncPgConnection,
201-
) -> Version {
202-
self.async_build(crate_id, published_by, connection)
203-
.await
204-
.unwrap_or_else(|e| {
205-
panic!("Unable to create version: {e:?}");
206-
})
207-
}
208-
209-
/// Consumes the builder and creates the version record in the database.
210-
///
211-
/// # Panics
212-
///
213-
/// Panics (and fails the test) if any part of inserting the version record fails.
214-
#[track_caller]
215-
pub fn expect_build(
216-
self,
217-
crate_id: i32,
218-
published_by: i32,
219-
connection: &mut PgConnection,
220155
) -> Version {
221156
self.build(crate_id, published_by, connection)
157+
.await
222158
.unwrap_or_else(|e| {
223159
panic!("Unable to create version: {e:?}");
224160
})

src/tests/routes/crates/versions/dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async fn dependencies() {
2323
.await;
2424
VersionBuilder::new("1.0.0")
2525
.dependency(&c2, None)
26-
.async_expect_build(c1.id, user.id, &mut conn)
26+
.expect_build(c1.id, user.id, &mut conn)
2727
.await;
2828

2929
let deps: Deps = anon

src/tests/routes/crates/versions/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn show_by_crate_name_and_version() {
1717
.size(1234)
1818
.checksum("c241cd77c3723ccf1aa453f169ee60c0a888344da504bee0142adb859092acb4")
1919
.rust_version("1.64")
20-
.async_expect_build(krate.id, user.id, &mut conn)
20+
.expect_build(krate.id, user.id, &mut conn)
2121
.await;
2222

2323
let url = "/api/v1/crates/foo_vers_show/2.0.0";
@@ -44,7 +44,7 @@ async fn show_by_crate_name_and_semver_no_published_by() {
4444
.expect_build(&mut async_conn)
4545
.await;
4646
let version = VersionBuilder::new("1.0.0")
47-
.async_expect_build(krate.id, user.id, &mut async_conn)
47+
.expect_build(krate.id, user.id, &mut async_conn)
4848
.await;
4949

5050
// Mimic a version published before we started recording who published versions

src/tests/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async fn record_rerendered_readme_time() {
1212
.expect_build(&mut conn)
1313
.await;
1414
let version = VersionBuilder::new("1.0.0")
15-
.async_expect_build(c.id, user.id, &mut conn)
15+
.expect_build(c.id, user.id, &mut conn)
1616
.await;
1717

1818
let mut conn = app.async_db_conn().await;

0 commit comments

Comments
 (0)