Skip to content

How to mock with rocket #923

Answered by open-schnick
open-schnick asked this question in Q&A
Discussion options

You must be logged in to vote

So it looks like i indeed missed something.
I thought you could just change a feature flag and sea-orm automatically uses a mocked implementation.
This is not the case.
You have to provide a different implementation of the sea_orm_rocket::Pool trait when running tests.
I implemented that by using a feature flag, that also enables the mock feature in sea orm.
Cargo.toml:

[features]
mock = ["sea-orm/mock"]

[dependencies]
sea-orm = { version = "0.9.0", features = ["sqlx-postgres", "runtime-tokio-native-tls"] }

Fixed code:

#[derive(Database, Debug)]
#[database("database")]
pub struct Db(SeaOrmPool);

#[derive(Debug)]
#[cfg_attr(not(feature = "mock"), derive(Clone))]
pub struct SeaOrmPool {
    

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by open-schnick
Comment options

You must be logged in to vote
4 replies
@open-schnick
Comment options

@open-schnick
Comment options

@billy1624
Comment options

@open-schnick
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants