Now when initializing the test database for sql tests, it will load the colors persona data into the database. This will provide a data set that tests can use without needing to call `wtt_load`. The main motivation is to allow for a separation of setup and test execution that requires crossing a transaction boundary. The pgTap tests are required to exectue as a single transaction, so that the rollback can reset the state, and each test can be isolated. However, can cause issues with some test senarios, particuarly with the use of some times releated functions like `current_timestamp` and `now` which return the time that the current transaction started. This creates an issue if a test relies on some setup that sets a time via `now`, then an update that expects a new time via `now`. See: https://www.postgresql.org/docs/13/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
31 lines
679 B
PL/PgSQL
31 lines
679 B
PL/PgSQL
begin;
|
|
-- wtt_load populates tables for the given test persona and set of aggregates.
|
|
-- Valid personas are:
|
|
-- * colors
|
|
-- * widgets
|
|
--
|
|
-- Valid aggregates:
|
|
-- * iam
|
|
-- * auth
|
|
-- * hosts
|
|
-- * targets
|
|
--
|
|
-- Note that some aggregates depend on data from other aggretates, so the order
|
|
-- that they are passed to this function matters.
|
|
create function wtt_load(persona text, variadic aggregates text[])
|
|
returns void
|
|
as $$
|
|
declare
|
|
agg text;
|
|
q text;
|
|
begin
|
|
foreach agg in array aggregates
|
|
loop
|
|
q = format('select _wtt_load_%I_%I()', persona, agg);
|
|
execute q;
|
|
end loop;
|
|
end;
|
|
$$ language plpgsql;
|
|
|
|
commit;
|