Skip to content

Commit

Permalink
refactor(api): [#143] remove Warp API implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jan 13, 2023
1 parent 337e12e commit 77ec521
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 1,150 deletions.
19 changes: 0 additions & 19 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
pub mod resource;
pub mod routes;
pub mod server;

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Debug)]
pub struct TorrentInfoQuery {
offset: Option<u32>,
limit: Option<u32>,
}

#[derive(Serialize, Debug)]
#[serde(tag = "status", rename_all = "snake_case")]
enum ActionStatus<'a> {
Ok,
Err { reason: std::borrow::Cow<'a, str> },
}

impl warp::reject::Reject for ActionStatus<'static> {}
230 changes: 0 additions & 230 deletions src/api/routes.rs

This file was deleted.

32 changes: 0 additions & 32 deletions src/api/server.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/jobs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod http_tracker;
pub mod torrent_cleanup;
pub mod tracker_api;
pub mod tracker_apis;
pub mod udp_tracker;
50 changes: 0 additions & 50 deletions src/jobs/tracker_api.rs

This file was deleted.

14 changes: 1 addition & 13 deletions tests/api/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ pub async fn assert_torrent_info(response: Response, torrent: Torrent) {
assert_eq!(response.json::<Torrent>().await.unwrap(), torrent);
}

pub async fn assert_auth_key(response: Response) -> AuthKey {
assert_eq!(response.status(), 200);
assert_eq!(response.headers().get("content-type").unwrap(), "application/json");
response.json::<AuthKey>().await.unwrap()
}

pub async fn assert_auth_key_utf8(response: Response) -> AuthKey {
assert_eq!(response.status(), 200);
assert_eq!(
Expand Down Expand Up @@ -58,17 +52,11 @@ pub async fn assert_bad_request(response: Response, body: &str) {

pub async fn assert_not_found(response: Response) {
assert_eq!(response.status(), 404);
// todo: missing header
// todo: missing header in the response
//assert_eq!(response.headers().get("content-type").unwrap(), "text/plain; charset=utf-8");
assert_eq!(response.text().await.unwrap(), "");
}

pub async fn assert_method_not_allowed(response: Response) {
assert_eq!(response.status(), 405);
assert_eq!(response.headers().get("content-type").unwrap(), "text/plain; charset=utf-8");
assert_eq!(response.text().await.unwrap(), "HTTP method not allowed");
}

pub async fn assert_torrent_not_known(response: Response) {
assert_eq!(response.status(), 200);
assert_eq!(response.headers().get("content-type").unwrap(), "application/json");
Expand Down
5 changes: 0 additions & 5 deletions tests/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub mod connection_info;
pub mod fixtures;
pub mod server;

pub enum Version {
Warp,
Axum,
}

/// It forces a database error by dropping all tables.
/// That makes any query fail.
/// code-review: alternatively we could inject a database mock in the future.
Expand Down
Loading

0 comments on commit 77ec521

Please sign in to comment.