sea-orm
sea-orm copied to clipboard
Axum mock example doesn't work for unit tests
Description
Due to https://github.com/SeaQL/sea-orm/issues/836 and https://github.com/SeaQL/sea-orm/issues/438, I see that you implemented https://github.com/SeaQL/sea-orm/pull/890 which is a rather hacky way to perform mock tests with (in my case) Axum, as also other users have already reported.
The examples provided only have integration tests, for which the hack works, however for unit tests, we would need to test every member of the workspace individually, as cargo will only compile one version of the sea orm crate.
Steps to Reproduce
Let's take for example, https://github.com/SeaQL/sea-orm/tree/75f7d4fa57aaeaeee88ca43dda99ed602cdcc930/examples/axum_example :
If I were to add to service/src/mutation.rs
@@ -51,3 +51,11 @@ impl Mutation {
Post::delete_many().exec(db).await
}
}
+
+#[test]
+#[cfg(test)]
+fn test() {
+ use sea_orm::MockDatabase;
+
+ let db = MockDatabase::new(sea_orm::DatabaseBackend::MySql);
+}
and test with cargo test --all --features axum-example-service/mock we get the error
Expected Behavior
Test runs successfully
Actual Behavior
error[E0277]: the trait bound `DatabaseConnection: Clone` is not satisfied
--> api/src/lib.rs:74:5
|
71 | #[derive(Clone)]
| ----- in this derive macro expansion
...
74 | conn: DatabaseConnection,
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `DatabaseConnection`
|
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
Reproduces How Often
Always reproducible
Workarounds
Test each package of a workspace individually or test all packages except the ones with mock and test these ones separately, which is not great
Reproducible Example
Example provided above as it is very simple
Versions
sea-orm-axum-example v0.1.0 (/tmp/sea-orm/examples/axum_example)
└── axum-example-api v0.1.0 (/tmp/sea-orm/examples/axum_example/api)
├── axum-example-service v0.1.0 (/tmp/sea-orm/examples/axum_example/service)
│ ├── entity v0.1.0 (/tmp/sea-orm/examples/axum_example/entity)
│ │ ├── sea-orm v1.1.5 (/tmp/sea-orm)
│ │ │ ├── sea-orm-macros v1.1.5 (proc-macro) (/tmp/sea-orm/sea-orm-macros)
│ │ │ │ ├── sea-bae v0.2.1 (proc-macro)
│ │ │ ├── sea-query v0.32.2
│ │ │ │ ├── sea-query-derive v0.4.2 (proc-macro)
│ │ │ ├── sea-query-binder v0.7.0
│ │ │ │ ├── sea-query v0.32.2 (*)
│ └── sea-orm v1.1.5 (/tmp/sea-orm) (*)
├── entity v0.1.0 (/tmp/sea-orm/examples/axum_example/entity) (*)
├── migration v0.1.0 (/tmp/sea-orm/examples/axum_example/migration)
│ └── sea-orm-migration v1.1.5 (/tmp/sea-orm/sea-orm-migration)
│ ├── sea-orm v1.1.5 (/tmp/sea-orm) (*)
│ ├── sea-orm-cli v1.1.5 (/tmp/sea-orm/sea-orm-cli)
│ │ ├── sea-schema v0.16.1
│ │ │ ├── sea-query v0.32.2 (*)
│ │ │ └── sea-schema-derive v0.3.0 (proc-macro)
│ ├── sea-schema v0.16.1 (*)