Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Florents-Tselai committed Nov 10, 2024
1 parent 60c3426 commit a6d384d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- run: |
sudo apt update
sudo apt install -y libpoppler-glib-dev pkg-config
sudo apt install -y libpoppler-glib-dev pkg-config wget
- uses: ankane/setup-postgres@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --load-extension=$(EXTENSION)

TEST_FILES = /tmp/pgintro.pdf /tmp/bad.pdf
TEST_FILES = /tmp/pgintro.pdf /tmp/bad.pdf /tmp/big.pdf
/tmp/pgintro.pdf:
cp test/pgintro.pdf $@
/tmp/bad.pdf:
echo 'not a pdf' >> $@
/tmp/big.pdf:
wget https://www.postgresql.org/files/documentation/pdf/17/postgresql-17-A4.pdf -O $@

installcheck: $(TEST_FILES)

Expand Down
3 changes: 2 additions & 1 deletion sql/pgpdf--0.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ CREATE TYPE pdf
(
INTERNALLENGTH = -1,
INPUT = pdf_in,
OUTPUT = pdf_out
OUTPUT = pdf_out,
STORAGE = extended
);

CREATE CAST (pdf AS text) WITH INOUT AS ASSIGNMENT;
Expand Down
11 changes: 11 additions & 0 deletions test/expected/pgpdf.out
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,14 @@ select pdf_read_bytes(pg_read_binary_file('/tmp/pgintro.pdf')) = '/tmp/pgintro.p
t
(1 row)

/* bigger files: >8KB */
CREATE TABLE pdfs(i serial primary key, d pdf);
INSERT INTO pdfs(d) VALUES('/tmp/pgintro.pdf');
INSERT INTO pdfs(d) VALUES('/tmp/big.pdf');
SELECT length(d::text) FROM pdfs
length
---------
4182
7055974
(2 rows)

9 changes: 7 additions & 2 deletions test/sql/pgpdf.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ SELECT '/tmp/pgintro.pdf'::pdf::text @@ to_tsquery('postgres');
SELECT '/tmp/pgintro.pdf'::pdf::text @@ to_tsquery('oracle');

/* Old functions mentioned in the blog post. Making sure they continue to work */

SELECT pdf_read_file('/tmp/pgintro.pdf') = '/tmp/pgintro.pdf'::pdf::text;
select pdf_read_bytes(pg_read_binary_file('/tmp/pgintro.pdf')) = '/tmp/pgintro.pdf'::pdf::text;
select pdf_read_bytes(pg_read_binary_file('/tmp/pgintro.pdf')) = '/tmp/pgintro.pdf'::pdf::text;

/* bigger files: >8KB */
CREATE TABLE pdfs(i serial primary key, d pdf);
INSERT INTO pdfs(d) VALUES('/tmp/pgintro.pdf');
INSERT INTO pdfs(d) VALUES('/tmp/big.pdf');
SELECT length(d::text) FROM pdfs

0 comments on commit a6d384d

Please sign in to comment.