From 0c146aa1b951207bd7454b037311debb560cc7ed Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Tue, 23 Apr 2024 15:06:32 -0400 Subject: [PATCH] Add pgrx test and reorganize PGXS tests Move the PGXS tests to a subdirectory separate testing PGXS from testing zip vs. Git bundling in `cicd.yml`. Then add a pgrx "hello world" project in `test/pgrx` and test it, too, including `pg_regress` tests. Update `/etc/sudoers` and the `PATH` environment variable to allow otherwise unprivileged users to do what they need to do. Also remove `nobody`. Copy-edit the README a bit and explicitly set the PATH environment variable in the `Dockerfile`, because `/etc/profile.d` scripts apparently don't run in GitHub workflows. --- .github/workflows/cicd.yml | 68 +++++++++++++++++--------- Dockerfile | 13 +++-- README.md | 64 +++++++++++++++--------- bin/pgrx-build-test | 2 +- test/.gitattributes | 2 +- test/pgrx/.cargo/config.toml | 3 ++ test/pgrx/.gitignore | 8 +++ test/pgrx/Cargo.toml | 32 ++++++++++++ test/pgrx/Makefile | 9 ++++ test/pgrx/hello.control | 5 ++ test/pgrx/results/base.out | 6 +++ test/pgrx/runtest.sh | 8 +++ test/pgrx/src/lib.rs | 34 +++++++++++++ test/pgrx/test/expected/base.out | 6 +++ test/pgrx/test/sql/base.sql | 1 + test/{ => pgxs}/META.json | 0 test/{ => pgxs}/Makefile | 7 ++- test/{ => pgxs}/no_cluster_test.sh | 0 test/{ => pgxs}/runtest.sh | 4 +- test/{ => pgxs}/test/expected/base.out | 0 test/{ => pgxs}/test/sql/base.sql | 0 test/{ => pgxs}/widget.control | 0 test/{ => pgxs}/widget.sql | 0 23 files changed, 219 insertions(+), 53 deletions(-) create mode 100644 test/pgrx/.cargo/config.toml create mode 100644 test/pgrx/.gitignore create mode 100644 test/pgrx/Cargo.toml create mode 100644 test/pgrx/Makefile create mode 100644 test/pgrx/hello.control create mode 100644 test/pgrx/results/base.out create mode 100755 test/pgrx/runtest.sh create mode 100644 test/pgrx/src/lib.rs create mode 100644 test/pgrx/test/expected/base.out create mode 100644 test/pgrx/test/sql/base.sql rename test/{ => pgxs}/META.json (100%) rename test/{ => pgxs}/Makefile (58%) rename test/{ => pgxs}/no_cluster_test.sh (100%) rename test/{ => pgxs}/runtest.sh (93%) rename test/{ => pgxs}/test/expected/base.out (100%) rename test/{ => pgxs}/test/sql/base.sql (100%) rename test/{ => pgxs}/widget.control (100%) rename test/{ => pgxs}/widget.sql (100%) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 509d72c..fc9e8fd 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -5,41 +5,65 @@ on: schedule: - cron: '0 14 3 * *' # Monthly at 2pm on the 3rd jobs: - test: - name: 🐘 PostgreSQL ${{ matrix.pg }} + pgxs: + name: 🐘 PGXS on Postgres ${{ matrix.pg }} runs-on: ubuntu-latest strategy: matrix: - pg: [16, 15, 14, 13, 12, 11, 10, 9.6, 9.5, 9.4, 9.3, 9.2, 9.1, '9.0', 8.4, 8.3, 8.2] + pg: [17, 16, 15, 14, 13, 12, 11, 10, 9.6, 9.5, 9.4, 9.3, 9.2, 9.1, '9.0', 8.4, 8.3, 8.2] steps: - uses: actions/checkout@v4 - name: Build Image run: docker build -t pgxn-tools-test . - # Test with Git repo - - name: Test Git as root - run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/runtest.sh ${{ matrix.pg }} git" - - name: Test Git as non-root - run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" -e AS_USER=worker pgxn-tools-test ./test/runtest.sh ${{ matrix.pg }} git" - - name: Test Git with extra file - run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/runtest.sh ${{ matrix.pg }} git yes" - - name: Test Git with archive-all + # First test system UID, otherwise it can't use files touched by root. + - name: Test with system UID + run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" -e AS_USER=pgxn_worker -e LOCAL_UID=$(id -u) pgxn-tools-test ./test/pgxs/runtest.sh ${{ matrix.pg }}" + - name: Test as root + run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/pgxs/runtest.sh ${{ matrix.pg }}" + + pgrx: + name: 🦀 pgrx on Postgres ${{ matrix.pg }} + runs-on: ubuntu-latest + strategy: + matrix: + pg: [16, 15, 14, 13, 12, 11] + steps: + - uses: actions/checkout@v4 + - name: Build Image + run: docker build -t pgxn-tools-test . + # First test system UID, otherwise it can't use files touched by root. + - name: Test with system UID + run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" -e AS_USER=pgxn_worker -e LOCAL_UID=$(id -u) pgxn-tools-test ./test/pgrx/runtest.sh ${{ matrix.pg }}" + - name: Test as root + run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/pgrx/runtest.sh ${{ matrix.pg }}" + + bundle: + name: ${{ matrix.util.icon }} Bundle with ${{ matrix.util.name }} + runs-on: ubuntu-latest + strategy: + matrix: + util: + - { icon: 🏷️, name: git, dir: "", run: ./test/pgxs } + - { icon: 🤐, name: zip, dir: /test, run: ./pgxs } + env: { PG_VERSION: 16 } + steps: + - uses: actions/checkout@v4 + - name: Build Image + run: docker build -t pgxn-tools-test . + - name: Test ${{ matrix.util.name }} + run: "docker run -w /repo --rm --volume \"$(pwd)${{ matrix.util.dir }}:/repo\" pgxn-tools-test ${{ matrix.util.run }}/runtest.sh ${{ env.PG_VERSION }} ${{ matrix.util[1] }}" + - name: Test ${{ matrix.util.name }} with extra file + run: "docker run -w /repo --rm --volume \"$(pwd)${{ matrix.util.dir }}:/repo\" pgxn-tools-test ${{ matrix.util.run }}/runtest.sh ${{ env.PG_VERSION }} ${{ matrix.util[1] }} yes" + - name: Test ${{ matrix.util.name }} with archive-all env: { GIT_ARCHIVE_CMD: archive-all } - run: "docker run -w /repo --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/runtest.sh ${{ matrix.pg }} git" - # Test without Git repo - - name: Test Zip as root - run: "docker run -w /repo --rm --volume \"$(pwd)/test:/repo\" pgxn-tools-test ./runtest.sh ${{ matrix.pg }} zip" - - name: Test Zip as non-root - run: "docker run -w /repo --rm --volume \"$(pwd)/test:/repo\" -e AS_USER=worker pgxn-tools-test ./runtest.sh ${{ matrix.pg }} zip" - - name: Test Zip with zip excluded file - run: "docker run -w /repo --rm --volume \"$(pwd)/test:/repo\" pgxn-tools-test ./runtest.sh ${{ matrix.pg }} zip yes" - # Test NO_CLUSTER + run: "docker run -w /repo --rm --volume \"$(pwd)${{ matrix.util.dir }}:/repo\" pgxn-tools-test ${{ matrix.util.run }}/runtest.sh ${{ env.PG_VERSION }} ${{ matrix.util[1] }}" - name: Test NO_CLUSTER - run: "docker run -w /repo -e NO_CLUSTER=1 --rm --volume \"$(pwd):/repo\" pgxn-tools-test ./test/no_cluster_test.sh ${{ matrix.pg }}" + run: "docker run -w /repo -e NO_CLUSTER=1 --rm --volume \"$(pwd)${{ matrix.util.dir }}:/repo\" pgxn-tools-test ${{ matrix.util.run }}/no_cluster_test.sh ${{ env.PG_VERSION }}" publish: # Publish for a tag starting with v. name: Push to Docker Hub - needs: test + needs: [pgxs, pgrx, bundle] if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: diff --git a/Dockerfile b/Dockerfile index bff3685..6e06835 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,21 +3,26 @@ FROM debian:bookworm-slim AS pgxn-config ADD https://salsa.debian.org/postgresql/postgresql-common/-/raw/master/pgdg/apt.postgresql.org.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/apt.postgresql.org.sh \ + # Install apt dependencies && apt-get update \ && apt-get install -y --no-install-recommends \ build-essential clang llvm llvm-dev llvm-runtime cmake libtoml-parser-perl \ pgxnclient libtap-parser-sourcehandler-pgtap-perl libipc-run-perl libtest-simple-perl sudo gosu \ ca-certificates gnupg2 zip unzip libarchive-tools curl git libicu-dev libxml2 locales ssl-cert \ + # Clean out unwanted stuff && apt-get -y purge postgresql-client-common \ && apt-get clean \ && rm -rf /var/cache/apt/* /var/lib/apt/lists/* \ + # Install CPAN dependencies && curl -L https://cpanmin.us/ -o cpanm && chmod +x cpanm \ && ./cpanm --notest PGXN::Meta::Validator \ && rm -r cpanm ~/.cpanm \ + # Configure sudoers to allow otherwise unprivileged users to do everything. && echo Defaults lecture = never >> /etc/sudoers \ + && echo 'Defaults env_keep += "CARGO_* RUSTUP_* PGRX_*"' >> /etc/sudoers \ && perl -i -pe 's/\bALL$/NOPASSWD:ALL/g' /etc/sudoers \ && echo 'postgres ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers \ - && echo 'nobody ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers \ + && perl -i -pe 's/^(Defaults\s+secure_path)/# $1/' /etc/sudoers \ # Ensure Git can do stuff in the working directory (issue #5). && git config --system --add safe.directory '*' \ # Install git-archive-all @@ -26,11 +31,11 @@ RUN chmod +x /usr/local/bin/apt.postgresql.org.sh \ && install -m 0755 git_archive_all.py "$(git --exec-path)/git-archive-all" \ && rm git_archive_all.py \ # Install the Rust toolchain - && curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | env CARGO_HOME=/usr/share/cargo RUSTUP_HOME=/usr/share/rustup bash -s -- -y \ - && echo "PATH=\"${PATH}:/usr/share/cargo/bin\"" > /etc/profile.d/cargo.sh + && curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | env CARGO_HOME=/usr/share/cargo RUSTUP_HOME=/usr/share/rustup bash -s -- -y --profile minimal --component rustfmt --component clippy \ + && chmod 0777 /usr/share/cargo /usr/share/cargo/bin COPY bin/* /usr/local/bin/ -ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 CARGO_HOME=/usr/share/cargo RUSTUP_HOME=/usr/share/rustup +ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 CARGO_HOME=/usr/share/cargo PGRX_HOME=/tmp/.pgrx RUSTUP_HOME=/usr/share/rustup PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/cargo/bin ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["/bin/bash"] diff --git a/README.md b/README.md index c5b5454..eed4f7f 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ releases to PGXN. The image contains these utilities: * [`pgxn`][cli]: The PGXN command-line client * [`pg_prove`]: Runs and harnessing pgTAP tests -* [`pg-start`] Pass a PostgreSQL major version to install and starts a PostgreSQL cluster -* [`pg-build-test`]: Builds and tests an extension in the current directory +* [`pg-start`] Installs a major version of PostgreSQL and starts a cluster +* [`pg-build-test`]: Builds and tests a [PGXS] extension in the current directory * [`pgrx-build-test`]: Builds and tests a [pgrx] extension in the current directory * [`pgxn-bundle`]: Validates the PGXN META.json file and bundles up a release * [`pgxn-release`]: Release to PGXN @@ -35,10 +35,12 @@ directory. ### Unprivileged User +**NOTE:** GitHub actions must be run as root. The options for unprivileged +users in this section will not work in that context. + By default the container runs as `root`. To run as an unprivileged user, pass the `AS_USER` environment variable and a user with that name will be created -with `sudo` privileges (already used by `pg-start`, `pg-build-test`, and -`pgrx-build-test`): +with `sudo` privileges (already used by `pg-start` and `pg-build-test`): ``` sh docker run -it --rm -w /repo -e AS_USER=worker \ @@ -56,9 +58,9 @@ docker run -it --rm -w /repo -e AS_USER=worker -e LOCAL_UID=$(id -u) \ sh -c 'sudo pg-start 14 && pg-build-test' ``` -### Sudo-Enabled Users +#### Included Users -The `nobody` user, included in the image, and the `postgres` user, created by +The `nobody` use, included in the image, and the `postgres` user, created by `pg-start`, also have full permission to use `sudo` without a password prompt. GitHub Workflow @@ -74,7 +76,7 @@ jobs: test: strategy: matrix: - pg: [16, 15, 14, 13, 12, 11, 10, 9.6, 9.5, 9.4, 9.3, 9.2, 9.1, 9.0, 8.4, 8.3, 8.2] + pg: [17, 16, 15, 14, 13, 12, 11, 10, 9.6, 9.5, 9.4, 9.3, 9.2, 9.1, 9.0, 8.4, 8.3, 8.2] name: 🐘 PostgreSQL ${{ matrix.pg }} runs-on: ubuntu-latest container: pgxn/pgxn-tools @@ -84,7 +86,7 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 - name: Test on PostgreSQL ${{ matrix.pg }} - run: pg-build-test # or pgrx-build-test for a pgrx extension + run: pg-build-test # or pgrx-build-test ``` This example demonstrates automatic publishing of a release whenever a tag is @@ -139,10 +141,10 @@ jobs: ### Unprivileged User Workflow -GitHub workflows [require the root user] to work with the workspace. To perform -tasks as an unprivileged user, first set things up as the root user, then use -[gosu] to execute a command as the `postgres` (can still run `sudo`) or `nobody` -(no privileges at all) user. For example: +GitHub workflows [require the root user] to work with the workspace. To +perform tasks as an unprivileged user, first set things up as the root user, +then use [gosu] to execute a command as the `postgres` (can run `sudo`) or +`nobody` (no privileges at all) user. For example: ``` yaml container: pgxn/pgxn-tools @@ -158,6 +160,18 @@ with the current directory's files all owned the newly-created `postgres` user, the last `run` commands executes `pg-build-test` as `postgres`, with the necessary permissions to write files to the workspace directory. +Alternatively, run the Docker image directly and set `AS_USER` to the desired +username and pass the GitHub worker UID via the `LOCAL_UID` variable: + +``` yaml + steps: + - uses: actions/checkout@v4 + - run: >- + docker run -w /repo --rm --volume "$(pwd):/repo" + -e AS_USER=pgxn_worker -e LOCAL_UID=$(id -u) + pgxn/pgxn-tools pg-start && pg-build-test +``` + Tools ----- @@ -229,8 +243,8 @@ pg_createcluster --start 16 my16 -p 5416 -- -A trust pg-build-test ``` -Simply builds, installs, and tests a PostgreSQL extension or other code in the -current directory. Effectively the equivalent of: +Simply builds, installs, and tests a [PGXS] PostgreSQL extension or other code +in the current directory. Effectively the equivalent of: ``` sh make @@ -256,9 +270,9 @@ pg-build-test pgrx-build-test ``` -Build, install, and test a PostgreSQL [pgrx] extension. It reads the required -version of [pgrx] from the `Cargo.toml` file, which must be v0.11.4 or higher. -Effectively the equivalent of: +Builds, installs, and tests a PostgreSQL [pgrx] extension. It reads the +required version of [pgrx] from the `Cargo.toml` file, which must be v0.11.4 +or higher. Effectively the equivalent of: ``` sh cargo install --locked cargo-pgrx --version ${PGRX_VERSION} @@ -273,11 +287,6 @@ all output. It will also run `make installcheck` if it finds a `Makefile` that appears to define the `installcheck` target, and emit the contents of the `regression.diffs` file if it fails. -**Note:** Since `pgrx` uses `sudo` to start the cluster as the `postgres` -user, so some environment variables may not be present while tests run. If -your Rust code reads environment variables it should guard against -`NotPresent` errors to handle unexpectedly missing environment variables. - ### [`pgxn-bundle`] ``` sh @@ -439,6 +448,15 @@ The image includes these packages; pass additional packages to * [ssl-cert](https://packages.debian.org/bookworm/ssl-cert) * [git-archive-all](https://github.com/Kentzo/git-archive-all) (run `git archive-all`) +### Rust Components + +The image includes the following Rust [components]; use `rustup component add` +to add additional components at runtime. + +* [rust minimal]: https://rust-lang.github.io/rustup/concepts/profiles.html +* [rustfmt]: https://github.com/rust-lang/rustfmt +* [clippy]: https://github.com/rust-lang/rust-clippy + Author ------ @@ -474,3 +492,5 @@ Copyright (c) 2020-2024 The PGXN Maintainers. Distributed under the [PostgreSQL TAP]: https://www.postgresql.org/docs/current/regress-tap.html [TAP]: https://testanything.org "Test Anything Protocol" [pgrx]: https://github.com/pgcentralfoundation/pgrx + [PGXS]: https://www.postgresql.org/docs/current/extend-pgxs.html + [components]: https://rust-lang.github.io/rustup/concepts/components.html diff --git a/bin/pgrx-build-test b/bin/pgrx-build-test index e0824b8..472901a 100755 --- a/bin/pgrx-build-test +++ b/bin/pgrx-build-test @@ -55,7 +55,7 @@ run [qw(cargo pgrx package --test --pg-config), $pg_config] or exit $? >> 8; # Install the extension. # (Must come before test: https://github.com/pgcentralfoundation/pgrx/issues/1670) say "### Installing $cfg->{package}{name}"; -run [qw(cargo pgrx install --test --pg-config), $pg_config] or exit $? >> 8; +run [qw(sudo cargo pgrx install --test --pg-config), $pg_config] or exit $? >> 8; # Run the tests as the postgres user. say "### Testing $cfg->{package}{name}"; diff --git a/test/.gitattributes b/test/.gitattributes index ea99adc..57182b0 100644 --- a/test/.gitattributes +++ b/test/.gitattributes @@ -1,4 +1,4 @@ .gitignore export-ignore .gitattributes export-ignore .github export-ignore -/runtest.sh export-ignore +runtest.sh export-ignore diff --git a/test/pgrx/.cargo/config.toml b/test/pgrx/.cargo/config.toml new file mode 100644 index 0000000..13c456b --- /dev/null +++ b/test/pgrx/.cargo/config.toml @@ -0,0 +1,3 @@ +[target.'cfg(target_os="macos")'] +# Postgres symbols won't be available until runtime +rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] diff --git a/test/pgrx/.gitignore b/test/pgrx/.gitignore new file mode 100644 index 0000000..9f24bed --- /dev/null +++ b/test/pgrx/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.idea/ +/target +*.iml +**/*.rs.bk +Cargo.lock +regression.* +results/ diff --git a/test/pgrx/Cargo.toml b/test/pgrx/Cargo.toml new file mode 100644 index 0000000..5ab1e93 --- /dev/null +++ b/test/pgrx/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[features] +default = ["pg13"] +pg11 = ["pgrx/pg11", "pgrx-tests/pg11" ] +pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ] +pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ] +pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ] +pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ] +pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ] +pg_test = [] + +[dependencies] +pgrx = "=0.11.4" + +[dev-dependencies] +pgrx-tests = "=0.11.4" + +[profile.dev] +panic = "unwind" + +[profile.release] +panic = "unwind" +opt-level = 3 +lto = "fat" +codegen-units = 1 diff --git a/test/pgrx/Makefile b/test/pgrx/Makefile new file mode 100644 index 0000000..d670038 --- /dev/null +++ b/test/pgrx/Makefile @@ -0,0 +1,9 @@ +EXTENSION = hello +EXTVERSION = 0.1.0 +TESTS = test/sql/base.sql +REGRESS = base +REGRESS_OPTS = --inputdir=test --load-extension=$(EXTENSION) +PG_CONFIG = pg_config + +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) diff --git a/test/pgrx/hello.control b/test/pgrx/hello.control new file mode 100644 index 0000000..57393f9 --- /dev/null +++ b/test/pgrx/hello.control @@ -0,0 +1,5 @@ +comment = 'hello: Created by pgrx' +default_version = '@CARGO_VERSION@' +module_pathname = '$libdir/hello' +relocatable = false +superuser = true diff --git a/test/pgrx/results/base.out b/test/pgrx/results/base.out new file mode 100644 index 0000000..50538d1 --- /dev/null +++ b/test/pgrx/results/base.out @@ -0,0 +1,6 @@ +SELECT hello_hello(); + hello_hello +-------------- + Hello, hello +(1 row) + diff --git a/test/pgrx/runtest.sh b/test/pgrx/runtest.sh new file mode 100755 index 0000000..6f98d8c --- /dev/null +++ b/test/pgrx/runtest.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -eu + +pgversion=$1 +cd "$(dirname "$0")" +pg-start "$pgversion" +pgrx-build-test diff --git a/test/pgrx/src/lib.rs b/test/pgrx/src/lib.rs new file mode 100644 index 0000000..1710f6e --- /dev/null +++ b/test/pgrx/src/lib.rs @@ -0,0 +1,34 @@ +use pgrx::prelude::*; + +pgrx::pg_module_magic!(); + +#[pg_extern] +fn hello_hello() -> &'static str { + "Hello, hello" +} + +#[cfg(any(test, feature = "pg_test"))] +#[pg_schema] +mod tests { + use pgrx::prelude::*; + + #[pg_test] + fn test_hello_hello() { + assert_eq!("Hello, hello", crate::hello_hello()); + } + +} + +/// This module is required by `cargo pgrx test` invocations. +/// It must be visible at the root of your extension crate. +#[cfg(test)] +pub 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![] + } +} diff --git a/test/pgrx/test/expected/base.out b/test/pgrx/test/expected/base.out new file mode 100644 index 0000000..50538d1 --- /dev/null +++ b/test/pgrx/test/expected/base.out @@ -0,0 +1,6 @@ +SELECT hello_hello(); + hello_hello +-------------- + Hello, hello +(1 row) + diff --git a/test/pgrx/test/sql/base.sql b/test/pgrx/test/sql/base.sql new file mode 100644 index 0000000..d72a423 --- /dev/null +++ b/test/pgrx/test/sql/base.sql @@ -0,0 +1 @@ +SELECT hello_hello(); diff --git a/test/META.json b/test/pgxs/META.json similarity index 100% rename from test/META.json rename to test/pgxs/META.json diff --git a/test/Makefile b/test/pgxs/Makefile similarity index 58% rename from test/Makefile rename to test/pgxs/Makefile index d4b0ab6..e8b5021 100644 --- a/test/Makefile +++ b/test/pgxs/Makefile @@ -1,6 +1,6 @@ EXTENSION = widget EXTVERSION = 1.0.0 -DATA = widget.sql +DATA = $(EXTENSION)--$(EXTVERSION).sql TESTS = test/sql/base.sql REGRESS = base REGRESS_OPTS = --inputdir=test @@ -8,3 +8,8 @@ PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) + +all: $(EXTENSION)--$(EXTVERSION).sql + +$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION).sql + @cp $^ $@ diff --git a/test/no_cluster_test.sh b/test/pgxs/no_cluster_test.sh similarity index 100% rename from test/no_cluster_test.sh rename to test/pgxs/no_cluster_test.sh diff --git a/test/runtest.sh b/test/pgxs/runtest.sh similarity index 93% rename from test/runtest.sh rename to test/pgxs/runtest.sh index 8a5e840..db762d1 100755 --- a/test/runtest.sh +++ b/test/pgxs/runtest.sh @@ -38,7 +38,7 @@ unzip "$zipfile" if [ "$expectutil" = "git" ]; then # Make sure runtest.sh was omitted thanks to .gitattributes. if [ -f "$prefix/runtests.sh" ]; then - echo 'ERROR: Zip file contains runtests.sh and should not' + echo 'ERROR: Zip file contains runtests.sh but should not' # shellcheck disable=SC2016 echo ' Did pgxn-bundle use `zip` instead of `git archive`?' exit 2 @@ -51,7 +51,7 @@ if [ "$expectutil" = "git" ]; then else # Make sure runtest.sh is included in the zip file. if [ ! -f "$prefix/runtest.sh" ]; then - echo 'ERROR: Zip file contains runtests.sh and should not' + echo 'ERROR: Zip file does not contain runtests.sh but should' # shellcheck disable=SC2016 echo ' Did pgxn-bundle use `git archive` instead of `zip`?' exit 2 diff --git a/test/test/expected/base.out b/test/pgxs/test/expected/base.out similarity index 100% rename from test/test/expected/base.out rename to test/pgxs/test/expected/base.out diff --git a/test/test/sql/base.sql b/test/pgxs/test/sql/base.sql similarity index 100% rename from test/test/sql/base.sql rename to test/pgxs/test/sql/base.sql diff --git a/test/widget.control b/test/pgxs/widget.control similarity index 100% rename from test/widget.control rename to test/pgxs/widget.control diff --git a/test/widget.sql b/test/pgxs/widget.sql similarity index 100% rename from test/widget.sql rename to test/pgxs/widget.sql