Skip to content

Commit

Permalink
Start pg_regress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 12, 2024
1 parent a77aa67 commit ba61d5d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ DISTNAME = $(shell perl -nE '/^name\s*=\s*"([^"]+)/ && do { say $$1; exit }'
DISTVERSION = $(shell perl -nE '/^version\s*=\s*"([^"]+)/ && do { say $$1; exit }' Cargo.toml)
PGRXV = $(shell perl -nE '/^pgrx\s+=\s"=?([^"]+)/ && do { say $$1; exit }' Cargo.toml)
PGV = $(shell perl -E 'shift =~ /(\d+)/ && say $$1' "$(shell $(PG_CONFIG) --version)")
TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test

PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

all: package

.DEFAULT_GOAL: package # Build jsonschmea for the PostgreSQL cluster identified by pg_config.
package:
Expand All @@ -16,9 +24,6 @@ install:
test:
@cargo test --all --no-default-features --features "pg$(PGV) pg_test" -- --nocapture

.PHONY: installcheck # An alias for the test target for PGXS compatability.
installcheck: test

.PHONY: cover # Run cover tests and generate & open a report.
cover:
@./.ci/test-cover "$(PGV)" "$(PGRXV)"
Expand All @@ -35,9 +40,11 @@ pg-version: Cargo.toml
install-pgrx: Cargo.toml
@cargo install --locked cargo-pgrx --version "$(PGRXV)"

.PHONY: pgrx-init # Initialize pgrx for the PostgreSQL version identified by pg_config.
pgrx-init: Cargo.toml
@cargo pgrx init "--pg$(PGV)"="$(PG_CONFIG)"

.PHONY: lint # Format and lint.
lint:
@cargo fmt --all --check
@cargo clippy --features "pg$(PGV)" --no-default-features
Expand Down
28 changes: 28 additions & 0 deletions results/jsonschema.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BEGIN;
CREATE EXTENSION jsonschema;
SELECT jsonschema_is_valid('{"type": "object"}'::jsonb);
jsonschema_is_valid
---------------------
t
(1 row)

SELECT jsonschema_is_valid('{"type": "object"}'::json);
jsonschema_is_valid
---------------------
t
(1 row)

-- pg_jsonschema-compatible functions
SELECT json_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::json);
json_matches_schema
---------------------
t
(1 row)

SELECT jsonb_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::jsonb);
jsonb_matches_schema
----------------------
t
(1 row)

ROLLBACK;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ mod tests {

#[pg_test]
fn test_jsonschema_is_valid() {
assert!(crate::json_schema_is_valid(Json(json!({"type": "object"})),));
assert!(crate::json_schema_is_valid(Json(json!({"type": "object"}))));
assert!(crate::jsonb_schema_is_valid(JsonB(
json!({"type": "object"})
)));
Expand Down
28 changes: 28 additions & 0 deletions test/expected/jsonschema.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BEGIN;
CREATE EXTENSION jsonschema;
SELECT jsonschema_is_valid('{"type": "object"}'::jsonb);
jsonschema_is_valid
---------------------
t
(1 row)

SELECT jsonschema_is_valid('{"type": "object"}'::json);
jsonschema_is_valid
---------------------
t
(1 row)

-- pg_jsonschema-compatible functions
SELECT json_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::json);
json_matches_schema
---------------------
t
(1 row)

SELECT jsonb_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::jsonb);
jsonb_matches_schema
----------------------
t
(1 row)

ROLLBACK;
11 changes: 11 additions & 0 deletions test/sql/jsonschema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BEGIN;
CREATE EXTENSION jsonschema;

SELECT jsonschema_is_valid('{"type": "object"}'::jsonb);
SELECT jsonschema_is_valid('{"type": "object"}'::json);

-- pg_jsonschema-compatible functions
SELECT json_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::json);
SELECT jsonb_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::jsonb);

ROLLBACK;

0 comments on commit ba61d5d

Please sign in to comment.