added tests for GetPrivateServicesViaPgxConnection and GetPrivateServicesViaPgxConnection

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-05 16:06:43 +02:00
parent 067982f772
commit ba574dc739
3 changed files with 123 additions and 6 deletions
@@ -164,7 +164,7 @@ func toSliceOfPtrs[T any](all []T) []*T {
return toret
}
func serviceDomainZone(svc service, ds []Domain) string {
func serviceDomainZone(svc Service, ds []Domain) string {
if domainFromSuffix(svc.Domain.String, svc.ProxyCluster.String) {
return svc.ProxyCluster.String
}
@@ -189,7 +189,7 @@ func domainFromSuffix(domain, suffix string) bool {
return domain == suffix || strings.HasSuffix(domain, "."+suffix)
}
func buildPrivateServiceCandidates(svcs []service, domains []Domain, proxyPeersByCluster map[string][]*nmdata.Peer) []networkmap.PrivateServiceCandidate {
func buildPrivateServiceCandidates(svcs []Service, domains []Domain, proxyPeersByCluster map[string][]*nmdata.Peer) []networkmap.PrivateServiceCandidate {
var out []networkmap.PrivateServiceCandidate
if len(proxyPeersByCluster) == 0 {
@@ -23,7 +23,7 @@ const (
`
)
func (pg *PgStore) GetPrivateServices(ctx context.Context, accountId string) ([]service, error) {
func (pg *PgStore) GetPrivateServices(ctx context.Context, accountId string) ([]Service, error) {
c, err := pg.Pool.Acquire(ctx)
if err != nil {
return nil, err
@@ -31,13 +31,13 @@ func (pg *PgStore) GetPrivateServices(ctx context.Context, accountId string) ([]
return GetPrivateServicesViaPgxConnection(ctx, c.Conn(), accountId)
}
func GetPrivateServicesViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) ([]service, error) {
func GetPrivateServicesViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) ([]Service, error) {
rows, err := conn.Query(ctx, GetServicesQuery, accountId)
if err != nil {
return nil, err
}
return pgx.CollectRows(rows, pgx.RowToStructByName[service])
return pgx.CollectRows(rows, pgx.RowToStructByName[Service])
}
func GetProxyTargetedDomainResourceIDsViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) (map[string]struct{}, error) {
@@ -58,7 +58,7 @@ func GetProxyTargetedDomainResourceIDsViaPgxConnection(ctx context.Context, conn
return toret, nil
}
type service struct {
type Service struct {
Enabled sql.NullBool
Private sql.NullBool
AccessGroups []string