laravel-rust 0.1.0

Laravel for Rust: a full-stack Rust web framework, inspired by PHP Laravel
Documentation
//! The database workflow store's test, which needs an application.

#![cfg(feature = "database-sqlite")]

use crate::context::Internals;
use crate::workflow::RunId;
use crate::workflow::store_contract::contract;

#[tokio::test]
async fn the_database_store_keeps_the_contract() {
    let directory = std::env::temp_dir().join(format!("laravel-workflow-store-{}", RunId::generate()));
    std::fs::create_dir_all(&directory).unwrap();
    let url = format!("sqlite://{}?mode=rwc", directory.join("store.sqlite").display());
    let app = crate::Application::configure()
        .replace_env(crate::config::Env::default())
        .with_config(move |config, _| {
            config.database.default = "primary".into();
            config
                .database
                .connections
                .insert("primary".into(), crate::config::database::ConnectionConfig::new(url));
        })
        .create();

    app.scope(async || {
        let connection = crate::db::default_connection().unwrap();
        for sql in [
            "CREATE TABLE workflow_runs (id VARCHAR(36) PRIMARY KEY, workflow VARCHAR(255) NOT NULL, \
             input TEXT NOT NULL, context TEXT NOT NULL, connection VARCHAR(255) NOT NULL, \
             queue VARCHAR(255) NOT NULL, status VARCHAR(16) NOT NULL, output TEXT, error TEXT, \
             wake_at TIMESTAMP(6), leased_until TIMESTAMP(6), lease_token VARCHAR(36), \
             created_at TIMESTAMP(6) NOT NULL, finished_at TIMESTAMP(6), \
             unique_key VARCHAR(255) UNIQUE, purge_data BOOLEAN NOT NULL DEFAULT FALSE)",
            "CREATE TABLE workflow_steps (id INTEGER PRIMARY KEY AUTOINCREMENT, run_id VARCHAR(36) NOT NULL, \
             kind VARCHAR(8) NOT NULL, name VARCHAR(255) NOT NULL, status VARCHAR(16) NOT NULL, \
             tries INTEGER NOT NULL, output TEXT, error TEXT, wake_at TIMESTAMP(6), started_at TIMESTAMP(6) NOT NULL, \
             finished_at TIMESTAMP(6), UNIQUE (run_id, kind, name))",
            "CREATE TABLE workflow_waits (token VARCHAR(255) NOT NULL, run_id VARCHAR(36) NOT NULL, \
             number INTEGER, resumed_at TIMESTAMP(6), PRIMARY KEY (token))",
            "CREATE TABLE workflow_resumes (run_id VARCHAR(36) NOT NULL, token VARCHAR(255) NOT NULL, \
             number BIGINT NOT NULL, value TEXT NOT NULL, created_at TIMESTAMP(6) NOT NULL, \
             PRIMARY KEY (run_id, token, number))",
            "CREATE TABLE workflow_attributes (run_id VARCHAR(36) NOT NULL, name VARCHAR(255) NOT NULL, \
             value VARCHAR(255) NOT NULL, PRIMARY KEY (run_id, name))",
        ] {
            connection
                .query(crate::db::sqlx::AssertSqlSafe(sql))
                .statement()
                .await
                .unwrap();
        }
        let database = crate::context::Context::expect("a test")
            .services()
            .built::<crate::db::DatabaseManager>()
            .unwrap();
        let store =
            crate::workflow::DatabaseStore::new(database, &crate::config::workflow::DatabaseStore::new()).unwrap();

        contract(&store).await;
    })
    .await;
    std::fs::remove_dir_all(directory).unwrap();
}