forked from rust-lang/crates.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util.rs
More file actions
47 lines (41 loc) · 1.31 KB
/
Copy pathtest_util.rs
File metadata and controls
47 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use diesel::prelude::*;
use crate::models::{Crate, NewTeam, Team};
use crates_io_test_utils::github::next_gh_id;
pub mod faker {
use super::*;
use anyhow::anyhow;
use crates_io_test_utils::builders::{CrateBuilder, UserBuilder};
use diesel_async::AsyncPgConnection;
pub async fn crate_and_version(
conn: &mut AsyncPgConnection,
name: &str,
description: &str,
user_id: i32,
downloads: i32,
) -> anyhow::Result<Crate> {
CrateBuilder::new(name, user_id)
.description(description)
.downloads(downloads)
.version("1.0.0")
.build(conn)
.await
.map_err(|err| anyhow!(err.to_string()))
}
pub async fn team(conn: &mut AsyncPgConnection, org: &str, team: &str) -> anyhow::Result<Team> {
let login = format!("github:{org}:{team}");
let team = NewTeam::builder()
.login(&login)
.org_id(next_gh_id())
.github_id(next_gh_id())
.name(team)
.build();
Ok(team.create_or_update(conn).await?)
}
pub async fn user(conn: &mut AsyncPgConnection, login: &str) -> QueryResult<i32> {
UserBuilder::new()
.with_username(login)
.new_user()
.insert(conn)
.await
}
}