Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test reorg #358

Merged
merged 32 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
75aba1f
bootstrap a `plrust-tests` create
eeeebbbbrrrr Jun 15, 2023
4a98659
split test from the lib.rs into different rs files
Jul 13, 2023
84205ba
update pgrx
Jul 14, 2023
8b9b75b
ci testing
Jul 18, 2023
0632b5f
pgx update to 0.9.8
Jul 20, 2023
b3e0dde
ci testing
Jul 20, 2023
0b75847
ci testing
Jul 20, 2023
909e984
ci testing
Jul 24, 2023
539f806
ci testing
Jul 25, 2023
5ffe1d0
add set to bash script `set -e`
Jul 25, 2023
b0022de
ci testing
Jul 26, 2023
3f6b82b
remove repeat tests
Jul 27, 2023
56014a2
add section that will run plrust test that are not ran with the plrus…
Jul 27, 2023
1a43a80
Add testing to ci in x86_64
Jul 27, 2023
1446445
First trial of getting trusted tests to run
BradyBonnette Jul 28, 2023
22c2be3
Set up plrust targets properly
BradyBonnette Jul 28, 2023
13266fc
install plrust before testing
BradyBonnette Jul 28, 2023
69fdc1a
not sure why this might be needed, but...
BradyBonnette Jul 28, 2023
e7ddfa2
try untrusted tests
BradyBonnette Jul 28, 2023
daae647
Allow unused pgrx::prelude in trusted tests
BradyBonnette Jul 28, 2023
6d4ef8b
Try out aarch64 tests
BradyBonnette Jul 28, 2023
f7d3b66
Try all versions
BradyBonnette Jul 31, 2023
e4eec4c
Re-introduces trusted path-traversal test after fixing work_dir issue
BradyBonnette Jul 31, 2023
1e77100
some cleanup of ci.yml
BradyBonnette Jul 31, 2023
3437334
change pgrx to 0.9.7
Aug 10, 2023
24c7c88
remove commented out code that lingered
Aug 22, 2023
41fc38e
update tempdir
Aug 22, 2023
2e75291
Update tempfile fully to 3.8.0
workingjubilee Aug 22, 2023
5762750
Run cargo fmt
workingjubilee Aug 22, 2023
b7b3328
Move back allowed_dependencies test for now
workingjubilee Aug 22, 2023
950e931
Include imports
workingjubilee Aug 22, 2023
bc71631
Include ludicrous indentation
workingjubilee Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,29 @@ jobs:
- name: Run cargo pgrx init
run: cargo pgrx init --pg$PG_VER $(which pg_config)

- name: Test PL/rust as "untrusted"
if: matrix.target == 'host'
run: cargo test --all --features "pg$PG_VER" --no-default-features
- name: Install PL/Rust as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && STD_TARGETS="aarch64-postgres-linux-gnu" ./build && echo "\q" | cargo pgrx run "pg$PG_VER" --features "trusted"

- name: Test PL/Rust package as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && cargo test --no-default-features --features "pg$PG_VER trusted"

- name: Test PL/rust as "trusted" (inc. postgrestd)
- name: Run PL/Rust integration tests as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && STD_TARGETS="aarch64-postgres-linux-gnu" ./build && cargo test --verbose --no-default-features --features "pg$PG_VER trusted"
run: cd plrust && echo "\q" | cargo pgrx run "pg$PG_VER" --features "trusted" && cd ../plrust-tests && cargo test --no-default-features --features "pg$PG_VER trusted"

- name: Install PL/Rust as "untrusted"
if: matrix.target == 'host'
run: cd plrust && STD_TARGETS="aarch64-postgres-linux-gnu" ./build && echo "\q" | cargo pgrx run "pg$PG_VER"

- name: Test PL/Rust package as "untrusted"
if: matrix.target == 'host'
run: cd plrust && cargo test --no-default-features --features "pg$PG_VER"

- name: Run PL/Rust integration tests as "untrusted"
if: matrix.target == 'host'
run: cd plrust && echo "\q" | cargo pgrx run "pg$PG_VER" && cd ../plrust-tests && cargo test --no-default-features --features "pg$PG_VER"

- name: Print sccache stats (after build)
run: sccache --show-stats
Expand Down Expand Up @@ -315,6 +331,9 @@ jobs:
- name: Print sccache stats
run: sccache --show-stats

- name: Test plrustc
run: cd plrustc && cargo test

- name: Install plrustc
run: cd plrustc && ./build.sh && cp ../build/bin/plrustc ~/.cargo/bin

Expand All @@ -324,13 +343,29 @@ jobs:
- name: Run 'cargo pgrx init' against system-level ${{ matrix.version }}
run: cargo pgrx init --pg$PG_VER $(which pg_config)

- name: Test PL/rust as "untrusted"
if: matrix.target == 'host'
run: cargo test --all --features "pg$PG_VER" --no-default-features
- name: Install PL/Rust as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && STD_TARGETS="x86_64-postgres-linux-gnu" ./build && echo "\q" | cargo pgrx run "pg$PG_VER" --features "trusted"

- name: Test PL/rust as "trusted" (inc. postgrestd)
- name: Test PL/Rust package as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && STD_TARGETS="x86_64-postgres-linux-gnu" ./build && cargo test --verbose --no-default-features --features "pg$PG_VER trusted"
run: cd plrust && cargo test --no-default-features --features "pg$PG_VER trusted"

- name: Run PL/Rust integration tests as "trusted"
if: matrix.target == 'postgrestd'
run: cd plrust && echo "\q" | cargo pgrx run "pg$PG_VER" --features "trusted" && cd ../plrust-tests && cargo test --no-default-features --features "pg$PG_VER trusted"

- name: Install PL/Rust as "untrusted"
if: matrix.target == 'host'
run: cd plrust && STD_TARGETS="x86_64-postgres-linux-gnu" ./build && echo "\q" | cargo pgrx run "pg$PG_VER"

- name: Test PL/Rust package as "untrusted"
if: matrix.target == 'host'
run: cd plrust && cargo test --no-default-features --features "pg$PG_VER"

- name: Run PL/Rust integration tests as "untrusted"
if: matrix.target == 'host'
run: cd plrust && echo "\q" | cargo pgrx run "pg$PG_VER" && cd ../plrust-tests && cargo test --no-default-features --features "pg$PG_VER"

- name: Print sccache stats
run: sccache --show-stats
Expand Down
56 changes: 36 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"plrust",
"plrust-trusted-pgrx",
"plrust-tests",
]
exclude = ["plrustc"]#, "builder"]

Expand Down
25 changes: 25 additions & 0 deletions plrust-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "plrust-tests"
version = "0.0.0"
edition = "2021"

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

[features]
default = ["pg13"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg_test = []
trusted = []

[dependencies]
pgrx = "=0.9.7"
tempfile = "3.8.0"
once_cell = "1.18.0"

[dev-dependencies]
pgrx-tests = "=0.9.7"
tempfile = "3.8.0"
once_cell = "1.18.0"
6 changes: 6 additions & 0 deletions plrust-tests/plrust_tests.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
comment = 'plrust_tests: Created by pgrx'
default_version = '@CARGO_VERSION@'
module_pathname = '$libdir/plrust_tests'
relocatable = false
superuser = true
requires = 'plrust'
30 changes: 30 additions & 0 deletions plrust-tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /bin/bash

VERSION=$1

if [ -z ${VERSION} ]; then
echo "usage: ./run-tests.sh pgXX [test-name]"
exit 1
fi

TEST_DIR=`pwd`

set -e

# install the plrust extension into the pgrx-managed postgres
echo "============================"
echo " installing plrust"
echo
cd ../plrust
echo "\q" | cargo pgrx run ${VERSION}

# run the test suite from this crate
cd ${TEST_DIR}

echo
echo "============================"
echo " running plrust-tests suite"
echo

cargo pgrx test ${VERSION} $2

42 changes: 42 additions & 0 deletions plrust-tests/src/alter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Portions Copyright 2020-2021 ZomboDB, LLC.
Portions Copyright 2021-2023 Technology Concepts & Design, Inc. <[email protected]>
All rights reserved.
Use of this source code is governed by the PostgreSQL license that can be found in the LICENSE.md file.
*/

#[cfg(any(test, feature = "pg_test"))]
#[pgrx::pg_schema]
mod tests {
use pgrx::prelude::*;

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "plrust functions cannot have their STRICT property altered"]
fn plrust_cant_change_strict_off() -> spi::Result<()> {
let definition = r#"
CREATE FUNCTION cant_change_strict_off()
RETURNS int
LANGUAGE plrust
AS $$ Ok(Some(1)) $$;
"#;
Spi::run(definition)?;
Spi::run("ALTER FUNCTION cant_change_strict_off() CALLED ON NULL INPUT")
}

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "plrust functions cannot have their STRICT property altered"]
fn plrust_cant_change_strict_on() -> spi::Result<()> {
let definition = r#"
CREATE FUNCTION cant_change_strict_on()
RETURNS int
LANGUAGE plrust
AS $$ Ok(Some(1)) $$;
"#;
Spi::run(definition)?;
Spi::run("ALTER FUNCTION cant_change_strict_on() RETURNS NULL ON NULL INPUT")
}
}
71 changes: 71 additions & 0 deletions plrust-tests/src/argument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Portions Copyright 2020-2021 ZomboDB, LLC.
Portions Copyright 2021-2023 Technology Concepts & Design, Inc. <[email protected]>
All rights reserved.
Use of this source code is governed by the PostgreSQL license that can be found in the LICENSE.md file.
*/

#[cfg(any(test, feature = "pg_test"))]
#[pgrx::pg_schema]
mod tests {
use pgrx::prelude::*;

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "parameter name \"a\" used more than once"]
fn plrust_dup_args() -> spi::Result<()> {
let definition = r#"
CREATE FUNCTION not_unique(a int, a int)
RETURNS int AS
$$
Ok(a)
$$ LANGUAGE plrust;
"#;
Spi::run(definition)?;
let result = Spi::get_one::<i32>("SELECT not_unique(1, 2);\n");
assert_eq!(Ok(Some(1)), result);
Ok(())
}

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "PL/Rust does not support unnamed arguments"]
fn plrust_defaulting_dup_args() -> spi::Result<()> {
let definition = r#"
CREATE FUNCTION not_unique(int, arg0 int)
RETURNS int AS
$$
Ok(arg0)
$$ LANGUAGE plrust;
"#;
Spi::run(definition)?;
let result = Spi::get_one::<i32>("SELECT not_unique(1, 2);\n");
assert_eq!(Ok(Some(1)), result);
Ok(())
}

#[pg_test]
#[search_path(@extschema@)]
#[should_panic(expected = "PL/Rust does not support unnamed arguments")]
fn unnamed_args() -> spi::Result<()> {
Spi::run("CREATE FUNCTION unnamed_arg(int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;")
}

#[pg_test]
#[search_path(@extschema@)]
#[should_panic(expected = "PL/Rust does not support unnamed arguments")]
fn named_unnamed_args() -> spi::Result<()> {
Spi::run("CREATE FUNCTION named_unnamed_arg(bob text, int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;")
}

#[pg_test]
#[search_path(@extschema@)]
#[should_panic(
expected = "is an invalid Rust identifier and cannot be used as an argument name"
)]
fn invalid_arg_identifier() -> spi::Result<()> {
Spi::run("CREATE FUNCTION invalid_arg_identifier(\"this isn't a valid rust identifier\" int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;")
}
}
Loading