Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ byteorder = "1"

[dev-dependencies]
tokio = { version = "1", features = ["test-util", "net", "rt-multi-thread"] }
tokio-test = "0.4"
async-trait = "0.1"
tokio-test = "0.4"
4 changes: 0 additions & 4 deletions examples/apiserver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{sync::Arc, collections::HashMap, io::Read};

use async_trait::async_trait;
use tokio::{net::{TcpListener, tcp::OwnedWriteHalf}, sync::RwLock};
use tokio_fastcgi::{Requests, RequestResult, Request};

Expand Down Expand Up @@ -80,7 +79,6 @@ impl HttpResponse {

/// Request handler trait. All request handlers have to implement this async trait.
/// The default implementation for every method returns the 405 (Method Not Allowed) error code.
#[async_trait]
trait RequestHandler {
async fn get(_store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, _selector: Option<u32>) -> Result<String, HttpResponse> {
Err(HttpResponse::e405())
Expand Down Expand Up @@ -115,7 +113,6 @@ impl Store {
/// Handles the REST API for quotes.
struct Quotes {}

#[async_trait]
impl RequestHandler for Quotes {
/// Get returns the quote stored for the given selector u32 or 404 (Not Found).
async fn get(store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, selector: Option<u32>) -> Result<String, HttpResponse> {
Expand Down Expand Up @@ -189,7 +186,6 @@ impl RequestHandler for Quotes {
/// Handle ping requests on /api/ping
struct Ping {}

#[async_trait]
impl RequestHandler for Ping {
async fn get(_store: Arc<RwLock<Store>>, _request: &Request<OwnedWriteHalf>, _selector: Option<u32>) -> Result<String, HttpResponse> {
Ok("pong".to_string())
Expand Down
17 changes: 3 additions & 14 deletions tests/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::sync::Arc;
use std::time::Duration;
use std::io::Read;
use std::convert::From;
use std::future::Future;
use tokio::io::AsyncWrite;
use async_trait::async_trait;

pub enum RecordType {
BeginRequest = 1,
Expand Down Expand Up @@ -53,16 +53,14 @@ pub fn create_record(request_type: RecordType, request_id: u8, padding: u8, data
record
}

#[async_trait]
pub trait TestCase {
fn get_input() -> Mock;
fn get_output() -> Mock;
async fn processor<W: AsyncWrite + Unpin + Send>(request: Arc<Request<W>>) -> RequestResult;
fn processor<W: AsyncWrite + Unpin + Send>(request: Arc<Request<W>>) -> impl Future<Output = RequestResult> + Send;
}

pub struct TestParamsInOut {}

#[async_trait]
impl TestCase for TestParamsInOut {
fn get_input() -> Mock {
Builder::new()
Expand Down Expand Up @@ -142,7 +140,6 @@ impl TestCase for TestParamsInOut {

pub struct TestRoleAuthorizer {}

#[async_trait]
impl TestCase for TestRoleAuthorizer {
fn get_input() -> Mock {
Builder::new()
Expand Down Expand Up @@ -175,7 +172,6 @@ impl TestCase for TestRoleAuthorizer {

pub struct TestRoleFilter {}

#[async_trait]
impl TestCase for TestRoleFilter {
fn get_input() -> Mock {
Builder::new()
Expand Down Expand Up @@ -219,7 +215,6 @@ impl TestCase for TestRoleFilter {

pub struct TestAbortRequest {}

#[async_trait]
impl TestCase for TestAbortRequest {
fn get_input() -> Mock {
Builder::new()
Expand All @@ -243,7 +238,6 @@ impl TestCase for TestAbortRequest {

pub struct TestAbortContinue {}

#[async_trait]
impl TestCase for TestAbortContinue {
fn get_input() -> Mock {
Builder::new()
Expand Down Expand Up @@ -279,7 +273,6 @@ impl TestCase for TestAbortContinue {

pub struct TestUnknownRoleReturn {}

#[async_trait]
impl TestCase for TestUnknownRoleReturn {
fn get_input() -> Mock {
Builder::new()
Expand All @@ -306,7 +299,6 @@ impl TestCase for TestUnknownRoleReturn {

pub struct TestUnknownRoleRequest {}

#[async_trait]
impl TestCase for TestUnknownRoleRequest {
fn get_input() -> Mock {
Builder::new()
Expand All @@ -331,7 +323,6 @@ impl TestCase for TestUnknownRoleRequest {

pub struct TestUnknownRequestType {}

#[async_trait]
impl TestCase for TestUnknownRequestType {
fn get_input() -> Mock {
Builder::new()
Expand All @@ -355,7 +346,6 @@ impl TestCase for TestUnknownRequestType {

pub struct TestGetValues {}

#[async_trait]
impl TestCase for TestGetValues {
fn get_input() -> Mock {
Builder::new()
Expand All @@ -380,7 +370,6 @@ impl TestCase for TestGetValues {
pub struct TestKeepConnection {
}

#[async_trait]
impl TestCase for TestKeepConnection {
fn get_input() -> Mock {
Builder::new()
Expand Down Expand Up @@ -423,4 +412,4 @@ impl TestCase for TestKeepConnection {
request.get_stderr().write(&[b'X', idx.as_bytes()[0] - b'1' + b'A']).await.unwrap();
RequestResult::Complete(0x11223344 * idx.parse().unwrap_or(0))
}
}
}