Skip to content

Commit

Permalink
Fix "no bin target" error and add a test
Browse files Browse the repository at this point in the history
The build error was:

    error: no bin target named `pgrx_embed_clerk_fdw`.

This is a side-effect of pgrx v0.12.x; pgcentralfoundation/pgrx#1888
documents the fix: adding a no-op embed target in
`src/bin/pgrx_embed_clerk_fdw.rs` and setting `lib.crate-type` to:

    crate-type = ["cdylib", "lib"]

Hopefully this funky workaround can be removed in the future.

The test simply ensures that `CREATE EXTENSION` works; the update to
`extension_ci.yml` ensures it passes on all supported Postgres versions.
  • Loading branch information
theory committed Dec 9, 2024
1 parent 4135ddf commit d78dddf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
53 changes: 20 additions & 33 deletions .github/workflows/extension_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]

[features]
default = ["pg17"]
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgrx_embed_clerk_fdw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::pgrx::pgrx_embed!();
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,37 @@ impl ForeignDataWrapper<ClerkFdwError> 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}");
}
}
}

0 comments on commit d78dddf

Please sign in to comment.