Files
threshold/internal/db/sqltest/tests/wh/upsert_user/insert.sql
T
Timothy Messier 9514a76289 test(sqltest): Fix tests due to new auth_token insert trigger
With the addition of an after insert trigger to the auth_token table,
entries are added to the wh_user_dimension table when auth token's are
inserted with the 'token issued' status. This caused a number of tests
to fail that assumed the user dimension table would be empty prior to
inserting sessions. This introduces a number of changes to the tests:

- In the test setup, auth tokens are not created with an explicit
  expiration time and status. The expiration time ensures that the
  tokens are 'valid' for the test. The status allows test to make
  assertions on tokens in different statuses, and allow the status to
  change during the test.
- Tests make the correct assertions on the number of entries in the user
  dimension table after test setup.
- User dimension tests modify a user after the standard setup to ensure
  that a new user dimension is added when a session is inserted.
2024-02-23 15:44:08 +00:00

21 lines
645 B
PL/PgSQL

-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: BUSL-1.1
-- insert tests that the wh_upsert_user function will do an insert when
-- no existing source wh_user_dimension exists.
begin;
select plan(3);
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');
-- ensure no existing dimensions
select is(count(*), 0::bigint) from wh_user_dimension where user_id = 'u_____wilson';
select lives_ok($$select wh_upsert_user('tok___wilson')$$);
-- upsert should insert a user_dimension
select is(count(*), 1::bigint) from wh_user_dimension where user_id = 'u_____wilson';
select * from finish();
rollback;