Skip to content

Commit

Permalink
Update test to work with windows temp path
Browse files Browse the repository at this point in the history
  • Loading branch information
robertozimek committed Nov 2, 2024
1 parent ce0f888 commit 79ab266
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
30 changes: 26 additions & 4 deletions h3/test/expected/type.out
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,31 @@ SELECT :hexagon = :asbigint::h3index;
--
-- TEST binary io
--
COPY (SELECT :hexagon) TO '/tmp/test.bin' (FORMAT binary);
CREATE TEMPORARY TABLE tmp (val h3index);
COPY tmp FROM '/tmp/test.bin' (FORMAT binary);
SELECT val = :hexagon FROM tmp WHERE val = :hexagon;
CREATE OR REPLACE FUNCTION copy_to_and_from_file(index h3index) RETURNS BOOLEAN LANGUAGE PLPGSQL AS
$$
DECLARE
result BOOL;
BEGIN
CREATE TEMPORARY TABLE from_temp (val h3index);
INSERT INTO from_temp (val) VALUES (index);
CREATE TEMPORARY TABLE to_tmp (val h3index);
IF (
SELECT CASE setting WHEN 'windows' THEN true ELSE false END AS isWindows
FROM pg_catalog.pg_file_settings
WHERE name = 'dynamic_shared_memory_type'
)
THEN
COPY (SELECT val FROM from_temp) TO 'C:\Windows\Temp\test.bin' (FORMAT binary);
COPY to_tmp FROM 'C:\Windows\Temp\test.bin' (FORMAT binary);
ELSE
COPY (SELECT val FROM from_temp) TO '/tmp/test.bin' (FORMAT binary);
COPY to_tmp FROM '/tmp/test.bin' (FORMAT binary);
END IF;

SELECT val = index into result FROM to_tmp WHERE val = index;
RETURN result;
END;
$$;
SELECT copy_to_and_from_file(:hexagon);
t

30 changes: 26 additions & 4 deletions h3/test/sql/type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@ SELECT :hexagon = :asbigint::h3index;
--
-- TEST binary io
--
COPY (SELECT :hexagon) TO '/tmp/test.bin' (FORMAT binary);
CREATE TEMPORARY TABLE tmp (val h3index);
COPY tmp FROM '/tmp/test.bin' (FORMAT binary);
SELECT val = :hexagon FROM tmp WHERE val = :hexagon;
CREATE OR REPLACE FUNCTION copy_to_and_from_file(index h3index) RETURNS BOOLEAN LANGUAGE PLPGSQL AS
$$
DECLARE
result BOOL;
BEGIN
CREATE TEMPORARY TABLE from_temp (val h3index);
INSERT INTO from_temp (val) VALUES (index);
CREATE TEMPORARY TABLE to_tmp (val h3index);
IF (
SELECT CASE setting WHEN 'windows' THEN true ELSE false END AS isWindows
FROM pg_catalog.pg_file_settings
WHERE name = 'dynamic_shared_memory_type'
)
THEN
COPY (SELECT val FROM from_temp) TO 'D:\a\h3-pg\test.bin' (FORMAT binary);
COPY to_tmp FROM 'D:\a\h3-pg\test.bin' (FORMAT binary);
ELSE
COPY (SELECT val FROM from_temp) TO '/tmp/test.bin' (FORMAT binary);
COPY to_tmp FROM '/tmp/test.bin' (FORMAT binary);
END IF;

SELECT val = index into result FROM to_tmp WHERE val = index;
RETURN result;
END;
$$;
SELECT copy_to_and_from_file(:hexagon);

0 comments on commit 79ab266

Please sign in to comment.