2023-02-02 17:15:17 -08:00
|
|
|
-- Copyright (c) HashiCorp, Inc.
|
2022-11-11 12:18:51 -08:00
|
|
|
-- SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2021-08-23 15:46:47 -04:00
|
|
|
-- session_update tests the wh_host_dimesion when
|
|
|
|
|
-- a session is inserted and then updated.
|
|
|
|
|
begin;
|
2022-02-14 16:30:18 -07:00
|
|
|
select plan(4);
|
2021-08-23 15:46:47 -04:00
|
|
|
|
|
|
|
|
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');
|
|
|
|
|
|
|
|
|
|
-- ensure no existing dimensions
|
|
|
|
|
select is(count(*), 0::bigint) from wh_host_dimension where organization_id = 'o_____widget';
|
|
|
|
|
|
2022-02-14 16:30:18 -07:00
|
|
|
-- insert first session, should result in a new host dimension
|
2021-08-23 15:46:47 -04:00
|
|
|
insert into session
|
2022-11-11 12:18:51 -08:00
|
|
|
( project_id , target_id , user_id , auth_token_id , certificate , endpoint , public_id)
|
2021-08-23 15:46:47 -04:00
|
|
|
values
|
2022-11-11 12:18:51 -08:00
|
|
|
('p____bwidget' , 't_________wb' , 'u_____walter' , 'tok___walter' , 'abc'::bytea , 'ep1' , 's1____walter');
|
|
|
|
|
insert into session_host_set_host
|
|
|
|
|
(session_id, host_set_id, host_id)
|
|
|
|
|
values
|
|
|
|
|
('s1____walter', 's___1wb-plghs', 'h_____wb__01-plgh');
|
2021-08-23 15:46:47 -04:00
|
|
|
|
|
|
|
|
select is(count(*), 1::bigint) from wh_host_dimension where organization_id = 'o_____widget';
|
|
|
|
|
|
|
|
|
|
-- update session, should not impact wh_host_dimension
|
|
|
|
|
update session set
|
|
|
|
|
version = 2
|
|
|
|
|
where
|
|
|
|
|
public_id = 's1____walter';
|
|
|
|
|
|
|
|
|
|
select is(count(*), 1::bigint) from wh_host_dimension where organization_id = 'o_____widget';
|
|
|
|
|
|
2022-02-14 16:30:18 -07:00
|
|
|
insert into host_dns_name
|
|
|
|
|
(host_id, name)
|
|
|
|
|
values
|
|
|
|
|
('h_____wb__01-plgh', 'new.big.widget');
|
|
|
|
|
|
|
|
|
|
-- update session, should not impact wh_host_dimension
|
|
|
|
|
update session set
|
|
|
|
|
version = 2
|
|
|
|
|
where
|
|
|
|
|
public_id = 's1____walter';
|
|
|
|
|
|
|
|
|
|
select is(count(*), 1::bigint) from wh_host_dimension where organization_id = 'o_____widget';
|
|
|
|
|
|
2021-08-23 15:46:47 -04:00
|
|
|
select * from finish();
|
|
|
|
|
rollback;
|