This sets up the configuration for running a new suite of tests that are
written in sql, to test the sql logic implemented in plpgsql functions
and triggers. It is primarily designed to provides tests for the data
warehouse functionality that is implemented purely in sql.
The infrastructure to run these tests leverages docker. It creates one
docker container using the `library/postgres` image and provisions the
database with the boundary sql migrations and test helper functions. A
separate docker container is run that has the pgtap extension and
pg_prove cli to execute the tests.
As noted, pgtap is used for the tests. This postgresql extension
provides a number of helpful assertion functions to make writing sql
tests easier. It also, along with the pg_prove cli, provides readable
test output.
Along with the new testing infrastructure this commit establishes a
baseline of tests for the wh_user_dimension:
- Unit tests for individual views and functions:
- whx_user_dimension_source
- whx_user_dimension_target
- wh_upsert_user
- Integration tests for that verify that the wh_user_dimension gets
populated correctly when sessions are inserted or updated. This
ensures that:
- the trigger runs on session insert
- the trigger results in the correct changes to the
wh_user_dimension.
This commit provides a `Makefile` to run the tests locally that provides
support for:
- Setting the postgres docker image to easily test multiple versions.
- Passing through options to pg_prove
- Passing the test list to run individual tests
- Additional targets to separately startup the database image to quickly
re-run tests while developing new tests.
Lastly configures circleci to run this test suite as a matrix build
in parallel with the other tests. The matrix build tests multiple
versions of postgres:
- latest
- 13-alpine
- 12-alpine
- 11-alpine
See:
https://pgtap.org/
50 lines
1.9 KiB
PL/PgSQL
50 lines
1.9 KiB
PL/PgSQL
-- source tests teh whx_user_dimension_source view.
|
|
begin;
|
|
select plan(4);
|
|
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');
|
|
|
|
-- auth_password_account
|
|
select is(s.*, row(
|
|
'u_____walter', 'Walter', 'None',
|
|
'apa___walter', 'password auth account', 'None', 'None',
|
|
'apm___widget', 'password auth method', 'Widget Auth Password', 'None',
|
|
'o_____widget', 'Widget Inc', 'None'
|
|
)::whx_user_dimension_source)
|
|
from whx_user_dimension_source as s
|
|
where s.user_id = 'u_____walter'
|
|
and s.auth_account_id = 'apa___walter';
|
|
|
|
select is(s.*, row(
|
|
'u_____walter', 'Walter', 'None',
|
|
'apa1__walter', 'password auth account', 'None', 'None',
|
|
'apm1__widget', 'password auth method', 'Widget Auth Password 1', 'None',
|
|
'o_____widget', 'Widget Inc', 'None'
|
|
)::whx_user_dimension_source)
|
|
from whx_user_dimension_source as s
|
|
where s.user_id = 'u_____walter'
|
|
and s.auth_account_id = 'apa1__walter';
|
|
|
|
select is(s.*, row(
|
|
'u_____warren', 'Warren', 'None',
|
|
'apa___warren', 'password auth account', 'None', 'None',
|
|
'apm___widget', 'password auth method', 'Widget Auth Password', 'None',
|
|
'o_____widget', 'Widget Inc', 'None'
|
|
)::whx_user_dimension_source)
|
|
from whx_user_dimension_source as s
|
|
where s.user_id = 'u_____warren'
|
|
and s.auth_account_id = 'apa___warren';
|
|
|
|
-- auth_oidc_account
|
|
select is(s.*, row(
|
|
'u_____walter', 'Walter', 'None',
|
|
'aoa___walter', 'password auth account', 'None', 'None',
|
|
'aom___widget', 'password auth method', 'None', 'None',
|
|
'o_____widget', 'Widget Inc', 'None'
|
|
)::whx_user_dimension_source)
|
|
from whx_user_dimension_source as s
|
|
where s.user_id = 'u_____walter'
|
|
and s.auth_account_id = 'aoa___walter';
|
|
|
|
select * from finish();
|
|
rollback;
|