added GetDomains test

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-05 12:37:58 +02:00
parent 1926e983fb
commit efe2eaeb09
3 changed files with 47 additions and 7 deletions

View File

@@ -11,11 +11,11 @@ const (
GetDomainsQuery = `
select domain, target_cluster
from domains
where account_id=$1
where account_id=$1 and domain<>'' and target_cluster<>''
`
)
func (pg *PgStore) GetDomains(ctx context.Context, accountId string) ([]domain, error) {
func (pg *PgStore) GetDomains(ctx context.Context, accountId string) ([]Domain, error) {
c, err := pg.Pool.Acquire(ctx)
if err != nil {
return nil, err
@@ -23,16 +23,16 @@ func (pg *PgStore) GetDomains(ctx context.Context, accountId string) ([]domain,
return GetDomainsViaPgxConnection(ctx, c.Conn(), accountId)
}
func GetDomainsViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) ([]domain, error) {
func GetDomainsViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) ([]Domain, error) {
rows, err := conn.Query(ctx, GetDomainsQuery, accountId)
if err != nil {
return nil, err
}
return pgx.CollectRows(rows, pgx.RowToStructByName[domain])
return pgx.CollectRows(rows, pgx.RowToStructByName[Domain])
}
type domain struct {
type Domain struct {
Domain sql.NullString
TargetCluster sql.NullString
}