diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bd8f714b4e0..b7d47237ee5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -173,7 +173,49 @@ jobs: uses: ./.github/actions/nix_upload_store if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }} + test_postgres: + name: Rust - test_postgres${{ matrix.test_projects != 'stable' && format('_{0}', matrix.test_projects) || '' }} + runs-on: ubuntu-22.04 + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: test + ports: + - 5433:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + defaults: + run: + shell: nix develop ./tools/nix#rust${{ matrix.test_projects == 'nightly' && '_nightly' || '' }} --keep CI --ignore-environment --command bash {0} + strategy: + fail-fast: false + matrix: + test_projects: + - stable + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + ref: ${{ github.event.inputs.commit_sha }} + + - name: Install Nix + uses: ./.github/actions/cache_nix + with: + cache-unique-id: ${{ matrix.test_projects }} + id: nix-installer + + - uses: ./.github/actions/cache_rust + with: + job_name: "${{ github.job }}-${{ matrix.test_projects }}" + + - name: Run postgres test on ${{ matrix.test_projects }} + run: make -f implementations/rust/Makefile test_postgres + + - name: Nix Upload Store + uses: ./.github/actions/nix_upload_store + if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }} check: name: Rust - check_${{ matrix.check_projects }} diff --git a/implementations/rust/Makefile b/implementations/rust/Makefile index d487fb52ba2..d7ebf49dbc3 100644 --- a/implementations/rust/Makefile +++ b/implementations/rust/Makefile @@ -48,6 +48,13 @@ nextest: nextest_%: cargo --locked nextest --config-file $(ROOT_DIR)/tools/nextest/.config/nextest.toml run -E 'package($*)' --no-fail-fast cargo --locked test --doc +test_postgres: + export OCKAM_POSTGRES_HOST=localhost + export OCKAM_POSTGRES_PORT=5433 + export OCKAM_POSTGRES_DATABASE_NAME=test + export OCKAM_POSTGRES_USER=postgres + export OCKAM_POSTGRES_PASSWORD=password + cargo --locked nextest --config-file $(ROOT_DIR)/tools/nextest/.config/nextest.toml run -E 'test(sql) or test(cli_state)' --no-fail-fast --test-threads 1 lint: lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_fmt_check: diff --git a/implementations/rust/ockam/ockam_node/src/storage/database/sqlx_database.rs b/implementations/rust/ockam/ockam_node/src/storage/database/sqlx_database.rs index 4658323f0b3..2b531aa8b99 100644 --- a/implementations/rust/ockam/ockam_node/src/storage/database/sqlx_database.rs +++ b/implementations/rust/ockam/ockam_node/src/storage/database/sqlx_database.rs @@ -19,9 +19,13 @@ use crate::database::database_configuration::DatabaseConfiguration; use crate::database::migrations::application_migration_set::ApplicationMigrationSet; use crate::database::migrations::node_migration_set::NodeMigrationSet; use crate::database::migrations::MigrationSet; -use crate::database::DatabaseType; +use crate::database::{ + DatabaseType, OCKAM_POSTGRES_DATABASE_NAME, OCKAM_POSTGRES_HOST, OCKAM_POSTGRES_PASSWORD, + OCKAM_POSTGRES_PORT, OCKAM_POSTGRES_USER, +}; use ockam_core::compat::rand::random_string; use ockam_core::compat::sync::Arc; +use ockam_core::env::get_env; use ockam_core::{Error, Result}; /// The SqlxDatabase struct is used to create a database: @@ -321,8 +325,20 @@ where let db = SqlxDatabase::create_sqlite(db_file.path()).await?; rethrow("SQLite on disk", f(db)).await?; + let host: Option = get_env(OCKAM_POSTGRES_HOST)?; + let port: Option = get_env(OCKAM_POSTGRES_PORT)?; + let database_name: String = + get_env(OCKAM_POSTGRES_DATABASE_NAME)?.unwrap_or("postgres".to_string()); + let user: Option = get_env(OCKAM_POSTGRES_USER)?; + let password: Option = get_env(OCKAM_POSTGRES_PASSWORD)?; + println!("boom: {host}:{port}/{database_name}/{user:?}/{password:?}"); + // only run the postgres tests if the OCKAM_POSTGRES_* environment variables are set if let Ok(db) = SqlxDatabase::create_new_postgres().await { + + if 2 == 1 + 1 { + panic!("boom: {host}:{port}/{database_name}/{user:?}/{password:?}"); + }; rethrow("Postgres local", f(db.clone())).await?; db.drop_all_postgres_tables().await?; };