-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(Backend): ✨ provide sorting for list_by* * update test
- Loading branch information
Showing
18 changed files
with
207 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,22 @@ | ||
use tonic::async_trait; | ||
|
||
#[async_trait] | ||
pub trait Case<S: Send + Sync> { | ||
const NAME: &'static str; | ||
|
||
async fn run(&self, state: &mut S) -> Result<(), String>; | ||
#[derive(Debug,thiserror::Error)] | ||
pub enum Error{ | ||
#[error("unreachable")] | ||
Unreachable | ||
} | ||
|
||
#[async_trait] | ||
trait Runable<S: Send + Sync> { | ||
async fn run(&self, state: &mut S) -> Result<(), String>; | ||
fn name(&self) -> &'static str; | ||
} | ||
// pub struct StackedTestcase<O> where Self:Sized{ | ||
// next:Box<dyn Testcase<O>> | ||
// } | ||
|
||
#[async_trait] | ||
impl<S: Send + Sync, Rhs: Case<S> + Send + Sync + 'static> Runable<S> for Rhs { | ||
async fn run(&self, state: &mut S) -> Result<(), String> { | ||
<Self as Case<S>>::run(self, state).await | ||
} | ||
// impl<I, O> Testcase<I> for StackedTestcase<O> { | ||
|
||
fn name(&self) -> &'static str { | ||
<Self as Case<S>>::NAME | ||
} | ||
} | ||
// } | ||
// #[async_trait] | ||
// pub trait Testcase<I,O>{ | ||
// fn run_inner(&self,state:I)->Result<I,Error>{ | ||
|
||
#[derive(Default)] | ||
pub struct CaseRunner<S: Send + Sync + Default> { | ||
case: Vec<Box<dyn Runable<S> + Send + Sync + 'static>>, | ||
state: S, | ||
} | ||
|
||
impl<S: Send + Sync + Default> CaseRunner<S> { | ||
pub fn add_case<Rhs: Case<S> + Send + Sync + 'static>(&mut self, case: Rhs) { | ||
self.case.push(Box::new(case)); | ||
} | ||
pub async fn run(mut self, title: &'static str) -> S { | ||
log::info!("Start testsuit {}", title); | ||
for (i, case) in self.case.into_iter().enumerate() { | ||
log::info!("Running case {} {}", i, case.name()); | ||
if let Err(err) = case.run(&mut self.state).await { | ||
log::error!("test fail: {}", err); | ||
break; | ||
} | ||
} | ||
log::info!("End"); | ||
|
||
self.state | ||
} | ||
} | ||
// } | ||
// fn stack(self,state:I,next:Box<dyn Testcase<O>>)->Result<O,Error>where O:From<I>; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.