\ir ./begin.sql

\ir ../_snowflake_template.sql
\ir ../_snowflake_init.sql

DROP FUNCTION snowflake_cluster_no();
DROP FUNCTION snowflake_island_no();

SELECT expect_rollback(
  $$SELECT _snowflake_init('10', '1')$$,
  '',
  'success with cluster_no_str=10, island_no_str=1'
) \gset

SELECT expect_raise(
  $$SELECT _snowflake_init('', '42')$$,
  'PG_SNOWFLAKE_CLUSTER_NO='''' environment variable must be a number%',
  'error: PG_SNOWFLAKE_CLUSTER_NO'
) \gset

SELECT expect_raise(
  $$SELECT _snowflake_init('10', '')$$,
  'PG_SNOWFLAKE_ISLAND_NO='''' environment variable must be a number%',
  'error: PG_SNOWFLAKE_ISLAND_NO'
) \gset

DROP FUNCTION _snowflake_init(text, text);
DROP FUNCTION _snowflake_template(text, text[]);

CREATE OR REPLACE FUNCTION snowflake_cluster_no() RETURNS integer LANGUAGE sql
  SET search_path FROM CURRENT AS 'SELECT 1';
CREATE OR REPLACE FUNCTION snowflake_island_no() RETURNS integer LANGUAGE sql
  SET search_path FROM CURRENT AS 'SELECT 1';

\ir ./rollback.sql
