Compare commits
3 Commits
35ccc235c8
...
testing
Author | SHA1 | Date | |
---|---|---|---|
d84078d6c3
|
|||
f14543af6b
|
|||
d260b2d676
|
@ -6,7 +6,7 @@ exclude = ["examples"]
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
authors = ["Martin Berg Alstad"]
|
||||
homepage = "emberal.github.io"
|
||||
homepage = "martials.no"
|
||||
|
||||
[package]
|
||||
name = "lib"
|
||||
|
@ -1,15 +0,0 @@
|
||||
[tasks.clippy]
|
||||
command = "cargo"
|
||||
args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]
|
||||
|
||||
[tasks.fmt]
|
||||
command = "cargo"
|
||||
args = ["fmt", "--all"]
|
||||
|
||||
[tasks.test]
|
||||
command = "cargo"
|
||||
args = ["test", "--all-features"]
|
||||
|
||||
[tasks.coverage]
|
||||
command = "cargo"
|
||||
args = ["llvm-cov", "--all-features"]
|
@ -2,7 +2,7 @@
|
||||
# see https://diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
||||
file = "tests/schema.rs"
|
||||
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
|
||||
|
||||
[migrations_directory]
|
||||
|
@ -5,15 +5,9 @@ use lib::diesel_crud_derive::{
|
||||
use lib::diesel_crud_trait::DieselCrudCreate;
|
||||
use test_containers::create_test_containers_pool;
|
||||
|
||||
mod schema;
|
||||
#[cfg(test)]
|
||||
pub mod test_containers;
|
||||
|
||||
diesel::table! {
|
||||
user (email) {
|
||||
#[max_length = 255]
|
||||
email -> Varchar,
|
||||
}
|
||||
}
|
||||
mod test_containers;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
@ -29,19 +23,19 @@ diesel::table! {
|
||||
DieselCrudUpdate,
|
||||
)]
|
||||
#[diesel_crud(insert = InsertUser)]
|
||||
#[diesel(table_name = user)]
|
||||
#[diesel(table_name = schema::user)]
|
||||
struct User {
|
||||
#[diesel_crud(pk)]
|
||||
email: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Insertable)]
|
||||
#[diesel(table_name = user)]
|
||||
#[diesel(table_name = schema::user)]
|
||||
struct InsertUser {
|
||||
email: String,
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_insert_user() {
|
||||
let container = create_test_containers_pool().await.unwrap();
|
||||
let mut conn = container.pool.get().await.unwrap();
|
||||
|
6
crates/tests/tests/schema.rs
Normal file
6
crates/tests/tests/schema.rs
Normal file
@ -0,0 +1,6 @@
|
||||
diesel::table! {
|
||||
user (email) {
|
||||
#[max_length = 255]
|
||||
email -> Varchar,
|
||||
}
|
||||
}
|
@ -1,19 +1,11 @@
|
||||
use diesel_migrations::EmbeddedMigrations;
|
||||
use lib::diesel::migration::run_migrations;
|
||||
use lib::test::test_containers::{ContainerError, TestContainer};
|
||||
use testcontainers_modules::postgres::Postgres;
|
||||
use testcontainers_modules::testcontainers::runners::AsyncRunner;
|
||||
use testcontainers_modules::testcontainers::{ContainerAsync, TestcontainersError};
|
||||
|
||||
pub async fn create_test_containers_pool() -> Result<TestContainer, ContainerError> {
|
||||
let test_container = lib::test::test_containers::create_test_containers_pool().await?;
|
||||
let pool = &test_container.pool;
|
||||
let connection = pool.get().await?;
|
||||
let connection = test_container.pool.get().await?;
|
||||
const MIGRATIONS: EmbeddedMigrations = diesel_migrations::embed_migrations!("./migrations");
|
||||
run_migrations(connection, MIGRATIONS).await?;
|
||||
Ok(test_container)
|
||||
}
|
||||
|
||||
pub async fn create_postgres_container() -> Result<ContainerAsync<Postgres>, TestcontainersError> {
|
||||
Postgres::default().start().await
|
||||
}
|
||||
|
4
justfile
4
justfile
@ -4,10 +4,10 @@ run:
|
||||
cargo run
|
||||
|
||||
fmt:
|
||||
cargo fmt
|
||||
cargo fmt --all
|
||||
|
||||
lint:
|
||||
cargo clippy
|
||||
cargo clippy --all-targets --all-features -- -D warnings
|
||||
|
||||
release:
|
||||
cargo build --release
|
||||
|
@ -13,8 +13,7 @@ pub async fn run_migrations<A>(
|
||||
where
|
||||
A: AsyncConnection<Backend = Pg> + 'static,
|
||||
{
|
||||
let mut async_wrapper: AsyncConnectionWrapper<A> =
|
||||
AsyncConnectionWrapper::from(async_connection);
|
||||
let mut async_wrapper = AsyncConnectionWrapper::<A>::from(async_connection);
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
async_wrapper.run_pending_migrations(migrations).unwrap();
|
||||
|
Reference in New Issue
Block a user