diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 3c25d6a..71d4af5 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -42,39 +42,26 @@ jobs: - name: Clippy run: cargo clippy - # figure out how to test work - # test: - # name: Run tests - # runs-on: ubuntu-22.04 - # steps: - # - uses: actions/checkout@v2 - # - name: Install Rust stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # toolchain: stable - # - uses: Swatinem/rust-cache@v2 - # with: - # prefix-key: "pgmq-extension-test" - # workspaces: | - # pgmq - # # Additional directories to cache - # cache-directories: | - # /home/runner/.pgrx - # - uses: ./.github/actions/pgx-init - # with: - # working-directory: ./ - # - name: test - # run: | - # sudo apt-get update && sudo apt-get install -y postgresql-server-dev-14 - # git clone https://github.com/pgpartman/pg_partman.git && \ - # cd pg_partman && \ - # sudo make install && cd ../ - # cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/15.4/pgrx-install/share/postgresql/extension/ - # cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/15.4/pgrx-install/lib/postgresql/ - # rm -rf ./target/pgrx-test-data-* || true - # pg_version=$(stoml Cargo.toml features.default) - # cargo pgrx run ${pg_version} --pgcli || true - # cargo pgrx test ${pg_version} + test: + runs-on: ubuntu-latest + container: pgxn/pgxn-tools + strategy: + matrix: + pg: [14, 15, 16, 17] + name: 🐘 Postgres ${{ matrix.pg }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Start PostgreSQL ${{ matrix.pg }} + run: pg-start ${{ matrix.pg }} + - name: Setup Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + - name: Install pg_partman + run: pgxn install pg_partman + - name: Test on PostgreSQL ${{ matrix.pg }} + run: pgrx-build-test publish: # only publish release events diff --git a/Cargo.toml b/Cargo.toml index 445c978..458efe4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg17"] diff --git a/src/bin/pgrx_embed_clerk_fdw.rs b/src/bin/pgrx_embed_clerk_fdw.rs new file mode 100644 index 0000000..5f5c4d8 --- /dev/null +++ b/src/bin/pgrx_embed_clerk_fdw.rs @@ -0,0 +1 @@ +::pgrx::pgrx_embed!(); diff --git a/src/lib.rs b/src/lib.rs index 263f5bb..f76ed4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,3 +393,37 @@ impl ForeignDataWrapper for ClerkFdw { Ok(()) } } + +/// This module is required by `cargo pgrx test` invocations. +/// It must be visible at the root of your extension crate. +#[cfg(test)] +mod pg_test { + pub fn setup(_options: Vec<&str>) { + // perform one-off initialization when the pg_test framework starts + } + + pub fn postgresql_conf_options() -> Vec<&'static str> { + // return any postgresql.conf settings that are required for your tests + vec![] + } +} + +// pgrx tests. +#[cfg(any(test, feature = "pg_test"))] +#[pg_schema] +mod tests { + use super::*; + #[pg_test] + fn create_fdw() { + // Just make sure it loads. + if let Err(e) = Spi::run( + r" + CREATE FOREIGN DATA WRAPPER clerk_wrapper + HANDLER clerk_fdw_handler + VALIDATOR clerk_fdw_validator + ", + ) { + panic!("CREATE FAILED: {e}"); + } + } +}