Skip to content

Commit 49f0b4a

Browse files
committed
fix: impl MockAuth
1 parent 4096088 commit 49f0b4a

9 files changed

+46
-51
lines changed

atcoder-problems-backend/tests/test_server_e2e_ac_ranking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use sql_client::PgPool;
6-
use tide::Result;
77
use tokio::task;
88

99
pub mod utils;
1010

1111
#[derive(Clone)]
1212
struct MockAuth;
1313

14-
#[async_trait]
14+
#[async_trait(?Send)]
1515
impl Authentication for MockAuth {
1616
async fn get_token(&self, _: &str) -> Result<String> {
1717
unimplemented!()
@@ -43,7 +43,7 @@ async fn setup() -> u16 {
4343
#[tokio::test]
4444
async fn test_ac_ranking() {
4545
let port = setup().await;
46-
let server = task::spawn(async move {
46+
let server = actix_rt::spawn(async move {
4747
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
4848
.await
4949
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_language_count.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use sql_client::PgPool;
6-
use tide::Result;
77
use tokio::task;
88

99
pub mod utils;
1010

1111
#[derive(Clone)]
1212
struct MockAuth;
1313

14-
#[async_trait]
14+
#[async_trait(?Send)]
1515
impl Authentication for MockAuth {
1616
async fn get_token(&self, _: &str) -> Result<String> {
1717
unimplemented!()
@@ -60,7 +60,7 @@ async fn setup() -> (u16, PgPool) {
6060
#[tokio::test]
6161
async fn test_language_count() {
6262
let (port, conn) = setup().await;
63-
let server = task::spawn(async move {
63+
let server = actix_rt::spawn(async move {
6464
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
6565
.await
6666
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_language_ranking.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use sql_client::PgPool;
6-
use tide::Result;
7-
use tokio::task;
87

98
pub mod utils;
109

1110
#[derive(Clone)]
1211
struct MockAuth;
1312

14-
#[async_trait]
13+
#[async_trait(?Send)]
1514
impl Authentication for MockAuth {
1615
async fn get_token(&self, _: &str) -> Result<String> {
1716
unimplemented!()
@@ -51,7 +50,7 @@ async fn setup() -> u16 {
5150
#[tokio::test]
5251
async fn test_language_ranking() {
5352
let port = setup().await;
54-
let server = task::spawn(async move {
53+
let server = actix_rt::spawn(async move {
5554
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
5655
.await
5756
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_problem_list.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use reqwest::header::SET_COOKIE;
56
use serde_json::{json, Value};
6-
use tide::Result;
7-
use tokio::task;
87

98
pub mod utils;
109

@@ -14,18 +13,18 @@ struct MockAuth;
1413
const VALID_CODE: &str = "VALID-CODE";
1514
const VALID_TOKEN: &str = "VALID-TOKEN";
1615

17-
#[async_trait]
16+
#[async_trait(?Send)]
1817
impl Authentication for MockAuth {
1918
async fn get_token(&self, code: &str) -> Result<String> {
2019
match code {
2120
VALID_CODE => Ok(VALID_TOKEN.to_owned()),
22-
_ => Err(anyhow::anyhow!("error").into()),
21+
_ => Err(actix_web::error::ErrorNotFound("error")),
2322
}
2423
}
2524
async fn get_user_id(&self, token: &str) -> Result<GitHubUserResponse> {
2625
match token {
2726
VALID_TOKEN => Ok(GitHubUserResponse::default()),
28-
_ => Err(anyhow::anyhow!("error").into()),
27+
_ => Err(actix_web::error::ErrorNotFound("error")),
2928
}
3029
}
3130
}
@@ -43,7 +42,7 @@ async fn setup() -> u16 {
4342
#[tokio::test]
4443
async fn test_list() {
4544
let port = setup().await;
46-
let server = task::spawn(async move {
45+
let server = actix_rt::spawn(async move {
4746
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
4847
.await
4948
.unwrap();
@@ -199,7 +198,7 @@ async fn test_list() {
199198
#[tokio::test]
200199
async fn test_invalid_token() {
201200
let port = setup().await;
202-
let server = task::spawn(async move {
201+
let server = actix_rt::spawn(async move {
203202
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
204203
.await
205204
.unwrap();
@@ -230,7 +229,7 @@ async fn test_invalid_token() {
230229
#[tokio::test]
231230
async fn test_list_item() {
232231
let port = setup().await;
233-
let server = task::spawn(async move {
232+
let server = actix_rt::spawn(async move {
234233
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
235234
.await
236235
.unwrap();
@@ -363,7 +362,7 @@ async fn test_list_item() {
363362
#[tokio::test]
364363
async fn test_list_delete() {
365364
let port = setup().await;
366-
let server = task::spawn(async move {
365+
let server = actix_rt::spawn(async move {
367366
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
368367
.await
369368
.unwrap();
@@ -437,7 +436,7 @@ async fn test_list_delete() {
437436
#[tokio::test]
438437
async fn test_register_twice() {
439438
let port = setup().await;
440-
let server = task::spawn(async move {
439+
let server = actix_rt::spawn(async move {
441440
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
442441
.await
443442
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_progress_reset.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use std::time::Duration;
6-
use tide::Result;
7-
use tokio::task;
87

98
pub mod utils;
109

1110
#[derive(Clone)]
1211
struct MockAuth;
13-
#[async_trait]
12+
13+
#[async_trait(?Send)]
1414
impl Authentication for MockAuth {
1515
async fn get_token(&self, _: &str) -> Result<String> {
1616
Ok(String::new())
@@ -34,7 +34,7 @@ fn url(path: &str, port: u16) -> String {
3434
#[tokio::test]
3535
async fn test_progress_reset() {
3636
let port = setup().await;
37-
let server = task::spawn(async move {
37+
let server = actix_rt::spawn(async move {
3838
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
3939
.await
4040
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_rated_point_sum_ranking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use sql_client::PgPool;
6-
use tide::Result;
7-
use tokio::task;
7+
88
mod utils;
99

1010
#[derive(Clone)]
1111
struct MockAuth;
12-
#[async_trait]
12+
#[async_trait(?Send)]
1313
impl Authentication for MockAuth {
1414
async fn get_token(&self, _: &str) -> Result<String> {
1515
unimplemented!()
@@ -42,7 +42,7 @@ async fn setup() -> u16 {
4242
#[tokio::test]
4343
async fn test_rated_point_sum_ranking() {
4444
let port = setup().await;
45-
let server = task::spawn(async move {
45+
let server = actix_rt::spawn(async move {
4646
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
4747
.await
4848
.unwrap();
@@ -144,7 +144,7 @@ async fn test_rated_point_sum_ranking() {
144144
#[tokio::test]
145145
async fn test_users_rated_point_sum_ranking() {
146146
let port = setup().await;
147-
let server = task::spawn(async move {
147+
let server = actix_rt::spawn(async move {
148148
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
149149
.await
150150
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_streak_ranking.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::{json, Value};
56
use sql_client::PgPool;
6-
use tide::Result;
7-
use tokio::task;
87

98
pub mod utils;
109

1110
#[derive(Clone)]
1211
struct MockAuth;
1312

14-
#[async_trait]
13+
#[async_trait(?Send)]
1514
impl Authentication for MockAuth {
1615
async fn get_token(&self, _: &str) -> Result<String> {
1716
unimplemented!()
@@ -43,7 +42,7 @@ async fn setup() -> u16 {
4342
#[tokio::test]
4443
async fn test_streak_ranking() {
4544
let port = setup().await;
46-
let server = task::spawn(async move {
45+
let server = actix_rt::spawn(async move {
4746
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
4847
.await
4948
.unwrap();

atcoder-problems-backend/tests/test_server_e2e_submissions.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
use actix_web::Result;
12
use async_trait::async_trait;
23
use atcoder_problems_backend::server::{run_server, Authentication, GitHubUserResponse};
34
use rand::Rng;
45
use serde_json::Value;
56
use sql_client::models::Submission;
67
use sql_client::PgPool;
7-
use tide::Result;
8-
use tokio::task;
98

109
pub mod utils;
1110

1211
#[derive(Clone)]
1312
struct MockAuth;
1413

15-
#[async_trait]
14+
#[async_trait(?Send)]
1615
impl Authentication for MockAuth {
1716
async fn get_token(&self, _: &str) -> Result<String> {
1817
unimplemented!()
@@ -65,7 +64,7 @@ async fn setup() -> u16 {
6564
#[tokio::test]
6665
async fn test_user_submissions() {
6766
let port = setup().await;
68-
let server = task::spawn(async move {
67+
let server = actix_rt::spawn(async move {
6968
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
7069
.await
7170
.unwrap();
@@ -96,7 +95,7 @@ async fn test_user_submissions() {
9695
#[tokio::test]
9796
async fn test_user_submissions_fromtime() {
9897
let port = setup().await;
99-
let server = task::spawn(async move {
98+
let server = actix_rt::spawn(async move {
10099
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
101100
.await
102101
.unwrap();
@@ -163,7 +162,7 @@ async fn test_user_submissions_fromtime() {
163162
#[tokio::test]
164163
async fn test_time_submissions() {
165164
let port = setup().await;
166-
let server = task::spawn(async move {
165+
let server = actix_rt::spawn(async move {
167166
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
168167
.await
169168
.unwrap();
@@ -187,7 +186,7 @@ async fn test_time_submissions() {
187186
#[tokio::test]
188187
async fn test_submission_count() {
189188
let port = setup().await;
190-
let server = task::spawn(async move {
189+
let server = actix_rt::spawn(async move {
191190
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
192191
.await
193192
.unwrap();
@@ -223,7 +222,7 @@ async fn test_submission_count() {
223222
#[tokio::test]
224223
async fn test_invalid_path() {
225224
let port = setup().await;
226-
let server = task::spawn(async move {
225+
let server = actix_rt::spawn(async move {
227226
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
228227
.await
229228
.unwrap();
@@ -251,7 +250,7 @@ async fn test_invalid_path() {
251250
#[tokio::test]
252251
async fn test_health_check() {
253252
let port = setup().await;
254-
let server = task::spawn(async move {
253+
let server = actix_rt::spawn(async move {
255254
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
256255
.await
257256
.unwrap();
@@ -269,7 +268,7 @@ async fn test_health_check() {
269268
#[tokio::test]
270269
async fn test_cors() {
271270
let port = setup().await;
272-
let server = task::spawn(async move {
271+
let server = actix_rt::spawn(async move {
273272
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
274273
.await
275274
.unwrap();
@@ -312,7 +311,7 @@ async fn test_cors() {
312311
#[tokio::test]
313312
async fn test_users_and_time() {
314313
let port = setup().await;
315-
let server = task::spawn(async move {
314+
let server = actix_rt::spawn(async move {
316315
let pg_pool = sql_client::initialize_pool(utils::get_sql_url_from_env())
317316
.await
318317
.unwrap();

0 commit comments

Comments
 (0)