Skip to content

Commit aadf9ca

Browse files
committed
sql-clientで#[sqlx::test]を使うようにした
1 parent ef9dfc8 commit aadf9ca

13 files changed

+94
-65
lines changed

atcoder-problems-backend/sql-client/tests/test_accepted_count.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use sql_client::accepted_count::AcceptedCountClient;
22
use sql_client::models::{Submission, UserProblemCount};
3+
use sql_client::PgPool;
34

45
mod utils;
56

6-
#[tokio::test]
7-
async fn test_accepted_count() {
8-
let pool = utils::initialize_and_connect_to_test_sql().await;
7+
#[sqlx::test]
8+
async fn test_accepted_count(pool: PgPool) {
9+
utils::initialize(&pool).await;
10+
911
let submissions = [
1012
Submission {
1113
id: 1,

atcoder-problems-backend/sql-client/tests/test_contest_problem.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use sql_client::contest_problem::ContestProblemClient;
22
use sql_client::models::ContestProblem;
3+
use sql_client::PgPool;
34

45
mod utils;
56

@@ -11,9 +12,10 @@ fn create_problem(id: i32) -> ContestProblem {
1112
}
1213
}
1314

14-
#[tokio::test]
15-
async fn test_contest_problem() {
16-
let pool = utils::initialize_and_connect_to_test_sql().await;
15+
#[sqlx::test]
16+
async fn test_contest_problem(pool: PgPool) {
17+
utils::initialize(&pool).await;
18+
1719
assert!(pool.load_contest_problem().await.unwrap().is_empty());
1820

1921
pool.insert_contest_problem(&[create_problem(1), create_problem(2)])

atcoder-problems-backend/sql-client/tests/test_language_count.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use sql_client::language_count::LanguageCountClient;
22
use sql_client::models::{Submission, UserLanguageCount, UserLanguageCountRank, UserProblemCount};
3+
use sql_client::PgPool;
34

45
mod utils;
56

6-
#[tokio::test]
7-
async fn test_language_count() {
8-
let pool = utils::initialize_and_connect_to_test_sql().await;
7+
#[sqlx::test]
8+
async fn test_language_count(pool: PgPool) {
9+
utils::initialize(&pool).await;
10+
911
let mut submissions = vec![
1012
Submission {
1113
id: 1,

atcoder-problems-backend/sql-client/tests/test_problem_info.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ async fn get_points(pool: &PgPool) -> Vec<(String, Option<f64>)> {
3232
.unwrap()
3333
}
3434

35-
#[tokio::test]
36-
async fn test_update_problem_solver_count() {
37-
let pool = utils::initialize_and_connect_to_test_sql().await;
35+
#[sqlx::test]
36+
async fn test_update_problem_solver_count(pool: PgPool) {
37+
utils::initialize(&pool).await;
3838

3939
assert!(get_solver(&pool).await.is_empty());
4040

@@ -79,12 +79,13 @@ async fn test_update_problem_solver_count() {
7979
assert_eq!(get_solver(&pool).await, vec![("problem".to_string(), 3)]);
8080
}
8181

82-
#[tokio::test]
83-
async fn test_update_problem_points() {
82+
#[sqlx::test]
83+
async fn test_update_problem_points(pool: PgPool) {
8484
let contest_id = "contest";
8585
let problem_id = "problem";
8686

87-
let pool = utils::initialize_and_connect_to_test_sql().await;
87+
utils::initialize(&pool).await;
88+
8889
pool.insert_contests(&[Contest {
8990
id: contest_id.to_string(),
9091
start_epoch_second: 1468670400,

atcoder-problems-backend/sql-client/tests/test_problem_list_manager.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
use sql_client::internal::problem_list_manager::{ListItem, ProblemList, ProblemListManager};
1+
use sql_client::{
2+
internal::problem_list_manager::{ListItem, ProblemList, ProblemListManager},
3+
PgPool,
4+
};
25

36
mod utils;
47

5-
#[tokio::test]
6-
async fn test_problem_list_manager() {
8+
#[sqlx::test]
9+
async fn test_problem_list_manager(pool: PgPool) {
710
let internal_user_id = "user_id";
811
let atcoder_user_id = "atcoder_id";
912
let list_name = "list_name";
1013
let problem_id = "problem_id";
11-
let pool = utils::initialize_and_connect_to_test_sql().await;
14+
15+
utils::initialize(&pool).await;
1216
utils::setup_internal_user(&pool, internal_user_id, atcoder_user_id).await;
1317

1418
assert!(

atcoder-problems-backend/sql-client/tests/test_problems_submissions.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ async fn get_from(pool: &PgPool, table: Table) -> Vec<(String, String, i64)> {
3636
.unwrap()
3737
}
3838

39-
async fn setup_contests() -> PgPool {
40-
let pool = utils::initialize_and_connect_to_test_sql().await;
39+
async fn setup_contests(pool: &PgPool) {
40+
utils::initialize(pool).await;
41+
4142
sqlx::query(
4243
r"
4344
INSERT INTO contests (id, start_epoch_second, duration_second, title, rate_change) VALUES
4445
('contest1', 1, 0, '', ''), ('contest2', 1, 0, '', '');
4546
",
4647
)
47-
.execute(&pool)
48+
.execute(pool)
4849
.await
4950
.unwrap();
50-
51-
pool
5251
}
5352

54-
#[tokio::test]
55-
async fn test_problem_info_aggrefator() {
53+
#[sqlx::test]
54+
async fn test_problem_info_aggrefator(pool: PgPool) {
5655
let ignored_submission = vec![Submission {
5756
id: 0,
5857
problem_id: "problem1".to_owned(),
@@ -85,7 +84,7 @@ async fn test_problem_info_aggrefator() {
8584
}];
8685

8786
{
88-
let pool = setup_contests().await;
87+
setup_contests(&pool).await;
8988

9089
pool.update_submissions(&ignored_submission).await.unwrap();
9190
pool.update_submissions_of_problems().await.unwrap();
@@ -110,7 +109,7 @@ async fn test_problem_info_aggrefator() {
110109
}
111110

112111
{
113-
let pool = setup_contests().await;
112+
setup_contests(&pool).await;
114113

115114
pool.update_submissions(&submissions2).await.unwrap();
116115
pool.update_submissions_of_problems().await.unwrap();
@@ -130,7 +129,7 @@ async fn test_problem_info_aggrefator() {
130129
}
131130

132131
{
133-
let pool = setup_contests().await;
132+
setup_contests(&pool).await;
134133

135134
pool.update_submissions(&submissions1).await.unwrap();
136135
pool.update_submissions_of_problems().await.unwrap();
@@ -150,7 +149,7 @@ async fn test_problem_info_aggrefator() {
150149
}
151150

152151
{
153-
let pool = setup_contests().await;
152+
setup_contests(&pool).await;
154153

155154
pool.update_submissions(&submissions2).await.unwrap();
156155
pool.update_submissions_of_problems().await.unwrap();

atcoder-problems-backend/sql-client/tests/test_progress_reset_manager.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
use sql_client::internal::progress_reset_manager::{
2-
ProgressResetItem, ProgressResetList, ProgressResetManager,
1+
use sql_client::{
2+
internal::progress_reset_manager::{
3+
ProgressResetItem, ProgressResetList, ProgressResetManager,
4+
},
5+
PgPool,
36
};
47

58
mod utils;
69

7-
#[tokio::test]
8-
async fn test_progress_reset_manager() {
10+
#[sqlx::test]
11+
async fn test_progress_reset_manager(pool: PgPool) {
912
let internal_user_id = "user_id";
1013
let atcoder_user_id = "atcoder_id";
1114
let problem_id = "problem_id";
1215
let reset_epoch_second = 42;
13-
let pool = utils::initialize_and_connect_to_test_sql().await;
16+
17+
utils::initialize(&pool).await;
1418
utils::setup_internal_user(&pool, internal_user_id, atcoder_user_id).await;
1519

1620
let list = pool

atcoder-problems-backend/sql-client/tests/test_rated_point_sum.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ async fn setup_contest_problems(pool: &PgPool) {
147147
}
148148
}
149149

150-
#[tokio::test]
151-
async fn test_update_rated_point_sum() {
152-
let pool = utils::initialize_and_connect_to_test_sql().await;
150+
#[sqlx::test]
151+
async fn test_update_rated_point_sum(pool: PgPool) {
152+
utils::initialize(&pool).await;
153153

154154
setup_contests(&pool).await;
155155
setup_contest_problems(&pool).await;
@@ -247,9 +247,9 @@ async fn test_update_rated_point_sum() {
247247
assert!(resp.is_err());
248248
}
249249

250-
#[tokio::test]
251-
async fn test_load_rated_point_sum_in_range() {
252-
let pool = utils::initialize_and_connect_to_test_sql().await;
250+
#[sqlx::test]
251+
async fn test_load_rated_point_sum_in_range(pool: PgPool) {
252+
utils::initialize(&pool).await;
253253

254254
setup_contests(&pool).await;
255255
setup_contest_problems(&pool).await;

atcoder-problems-backend/sql-client/tests/test_simple_client.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use sql_client::models::{Contest, Problem};
22
use sql_client::simple_client::SimpleClient;
3+
use sql_client::PgPool;
34

45
mod utils;
56

6-
#[tokio::test]
7-
async fn test_insert_contests() {
8-
let pool = utils::initialize_and_connect_to_test_sql().await;
7+
#[sqlx::test]
8+
async fn test_insert_contests(pool: PgPool) {
9+
utils::initialize(&pool).await;
10+
911
assert!(pool.load_contests().await.unwrap().is_empty());
1012
pool.insert_contests(&[Contest {
1113
id: "contest1".to_string(),
@@ -31,9 +33,10 @@ async fn test_insert_contests() {
3133
.unwrap();
3234
}
3335

34-
#[tokio::test]
35-
async fn test_insert_problems() {
36-
let pool = utils::initialize_and_connect_to_test_sql().await;
36+
#[sqlx::test]
37+
async fn test_insert_problems(pool: PgPool) {
38+
utils::initialize(&pool).await;
39+
3740
assert!(pool.load_problems().await.unwrap().is_empty());
3841
pool.insert_problems(&[Problem {
3942
id: "problem1".to_string(),

atcoder-problems-backend/sql-client/tests/test_streak.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use sql_client::models::UserStreak;
22
use sql_client::streak::StreakClient;
33
use sql_client::submission_client::{SubmissionClient, SubmissionRequest};
4+
use sql_client::PgPool;
45

56
mod utils;
67

7-
#[tokio::test]
8-
async fn test_streak_ranking() {
9-
let pool = utils::initialize_and_connect_to_test_sql().await;
8+
#[sqlx::test]
9+
async fn test_streak_ranking(pool: PgPool) {
10+
utils::initialize(&pool).await;
11+
1012
sqlx::query(
1113
r"
1214
INSERT INTO submissions (id, epoch_second, problem_id, contest_id, user_id, language, point, length, result) VALUES

0 commit comments

Comments
 (0)