Pull request 2155: AG-27492-client-persistent-index

Squashed commit of the following:

commit 1f99640f9f0a24ade7d2325737edf83ad0da3895
Merge: 5a9211e8c 9276afd79
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Feb 27 13:13:03 2024 +0300

    Merge branch 'master' into AG-27492-client-persistent-index

commit 5a9211e8c7832700ae4f58cea25ad38ccba98efa
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Feb 22 19:08:35 2024 +0300

    all: add todo

commit a4fc94904b0b05ed5ca5ba270125a7d7fb1e6817
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Wed Feb 21 14:48:33 2024 +0300

    all: client persistent index
This commit is contained in:
Stanislav Chzhen
2024-02-27 13:48:11 +03:00
parent 9276afd79d
commit 31c3d7d302
12 changed files with 203 additions and 169 deletions

View File

@@ -4,6 +4,7 @@ import (
"net/netip"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/client"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/schedule"
"github.com/stretchr/testify/assert"
@@ -14,12 +15,12 @@ var testIPv4 = netip.AddrFrom4([4]byte{1, 2, 3, 4})
// newIDIndex is a helper function that returns a client index filled with
// persistent clients from the m. It also generates a UID for each client.
func newIDIndex(m []*persistentClient) (ci *clientIndex) {
ci = NewClientIndex()
func newIDIndex(m []*client.Persistent) (ci *client.Index) {
ci = client.NewIndex()
for _, c := range m {
c.UID = MustNewUID()
ci.add(c)
c.UID = client.MustNewUID()
ci.Add(c)
}
return ci
@@ -35,24 +36,24 @@ func TestApplyAdditionalFiltering(t *testing.T) {
}, nil)
require.NoError(t, err)
Context.clients.clientIndex = newIDIndex([]*persistentClient{{
Context.clients.clientIndex = newIDIndex([]*client.Persistent{{
ClientIDs: []string{"default"},
UseOwnSettings: false,
safeSearchConf: filtering.SafeSearchConfig{Enabled: false},
SafeSearchConf: filtering.SafeSearchConfig{Enabled: false},
FilteringEnabled: false,
SafeBrowsingEnabled: false,
ParentalEnabled: false,
}, {
ClientIDs: []string{"custom_filtering"},
UseOwnSettings: true,
safeSearchConf: filtering.SafeSearchConfig{Enabled: true},
SafeSearchConf: filtering.SafeSearchConfig{Enabled: true},
FilteringEnabled: true,
SafeBrowsingEnabled: true,
ParentalEnabled: true,
}, {
ClientIDs: []string{"partial_custom_filtering"},
UseOwnSettings: true,
safeSearchConf: filtering.SafeSearchConfig{Enabled: true},
SafeSearchConf: filtering.SafeSearchConfig{Enabled: true},
FilteringEnabled: true,
SafeBrowsingEnabled: false,
ParentalEnabled: false,
@@ -120,7 +121,7 @@ func TestApplyAdditionalFiltering_blockedServices(t *testing.T) {
}, nil)
require.NoError(t, err)
Context.clients.clientIndex = newIDIndex([]*persistentClient{{
Context.clients.clientIndex = newIDIndex([]*client.Persistent{{
ClientIDs: []string{"default"},
UseOwnBlockedServices: false,
}, {