From ec3e37456e27b2dc111daab7a5682b1f17350ac1 Mon Sep 17 00:00:00 2001 From: pascal Date: Wed, 5 Aug 2026 16:33:48 +0200 Subject: [PATCH] use Exec instead of Query for inserts and assert every insert error --- .../pgsql/account_settings_test.go | 2 +- .../network_map_db/pgsql/group_test.go | 2 +- .../network_map_db/pgsql/service_test.go | 40 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/integration_tests/management/network_map_db/pgsql/account_settings_test.go b/integration_tests/management/network_map_db/pgsql/account_settings_test.go index 2c01eb062..53d485dc3 100644 --- a/integration_tests/management/network_map_db/pgsql/account_settings_test.go +++ b/integration_tests/management/network_map_db/pgsql/account_settings_test.go @@ -13,7 +13,7 @@ import ( func TestGetAccountSettings(t *testing.T) { ctx := context.TODO() - _, err := pgstore.Pool.Query(ctx, + _, err := pgstore.Pool.Exec(ctx, `insert into accounts (id, settings_peer_login_expiration_enabled, settings_peer_login_expiration, settings_peer_inactivity_expiration_enabled, settings_peer_inactivity_expiration, settings_dns_domain, settings_ipv6_enabled_groups, settings_routing_peer_dns_resolution_enabled, settings_lazy_connection_enabled, settings_auto_update_version, settings_auto_update_always, settings_metrics_push_enabled) diff --git a/integration_tests/management/network_map_db/pgsql/group_test.go b/integration_tests/management/network_map_db/pgsql/group_test.go index 343daab96..c56859634 100644 --- a/integration_tests/management/network_map_db/pgsql/group_test.go +++ b/integration_tests/management/network_map_db/pgsql/group_test.go @@ -52,7 +52,7 @@ func TestGetGroupsWithoutExpectedFields(t *testing.T) { "insert into accounts (id) VALUES($1)", acctId) assert.NoError(t, err) - _, err = s.Pool.Query(ctx, + _, err = s.Pool.Exec(ctx, "insert into groups (id, account_id) VALUES('g2-test-group-id-1',$1)", acctId) assert.NoError(t, err) diff --git a/integration_tests/management/network_map_db/pgsql/service_test.go b/integration_tests/management/network_map_db/pgsql/service_test.go index a23fad55d..7292187a7 100644 --- a/integration_tests/management/network_map_db/pgsql/service_test.go +++ b/integration_tests/management/network_map_db/pgsql/service_test.go @@ -5,22 +5,23 @@ import ( "database/sql" "testing" - networkmap_pgsql "github.com/netbirdio/netbird/management/internals/network_map_db/pgsql" "github.com/stretchr/testify/assert" + + networkmap_pgsql "github.com/netbirdio/netbird/management/internals/network_map_db/pgsql" ) func TestGetPrivateServicesViaPgxConnection(t *testing.T) { ctx := context.TODO() - _, err := pgstore.Pool.Query(ctx, + _, err := pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, private, access_groups, proxy_cluster, domain) values('service-1','account-1',true,true,'["group-one-resource-id"]','test-1.com','test-2.com')`) assert.NoError(t, err) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, private, access_groups, proxy_cluster, domain) values('service-2','account-1',true,true,'["group-one-resource-id","group-two-resources-id"]','test-3.com','test-4.com')`) assert.NoError(t, err) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, private, access_groups, proxy_cluster, domain) values('service-3','account-1',null,null,null,null,null)`) assert.NoError(t, err) @@ -53,56 +54,61 @@ func TestGetPrivateServicesViaPgxConnection(t *testing.T) { func TestGetProxyTargetedDomainResourceIDsViaPgxConnection(t *testing.T) { ctx := context.TODO() - _, err := pgstore.Pool.Query(ctx, + _, err := pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, terminated) values('service-4','account-1',true,false)`) assert.NoError(t, err) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-1','account-1','service-4',true,'domain')`) + assert.NoError(t, err) // id shouldn't be returned as the taget_type is not "domain" - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-2','account-1','service-4',true,'cluster')`) assert.NoError(t, err) // id shouldn't be included as the target is disabled - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-3','account-1','service-4',false,'domain')`) assert.NoError(t, err) // id shouldn't be included as the service is disabled - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, terminated) values('service-5','account-1',false,false)`) - _, err = pgstore.Pool.Query(ctx, + assert.NoError(t, err) + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-4','account-1','service-5',false,'domain')`) assert.NoError(t, err) // id shouldn't be included as the service is terminated (explicitly) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, terminated) values('service-6','account-1',true,true)`) - _, err = pgstore.Pool.Query(ctx, + assert.NoError(t, err) + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-5','account-1','service-6',true,'domain')`) assert.NoError(t, err) // id shouldn't be included as the service is terminated (implicitly) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, terminated) values('service-7','account-1',true,null)`) - _, err = pgstore.Pool.Query(ctx, + assert.NoError(t, err) + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-6','account-1','service-7',true,'domain')`) assert.NoError(t, err) - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into services (id, account_id, enabled, terminated) values('service-8','account-1',true,false)`) - _, err = pgstore.Pool.Query(ctx, + assert.NoError(t, err) + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values('target-7','account-1','service-8',true,'domain')`) assert.NoError(t, err) // id shouldn't be returned as the taget_id is null - _, err = pgstore.Pool.Query(ctx, + _, err = pgstore.Pool.Exec(ctx, `insert into targets (target_id, account_id, service_id, enabled, target_type) values(null,'account-1','service-4',true,'cluster')`) assert.NoError(t, err)