mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-01-04 13:07:20 +03:00
6363f8a2e7
Squashed commit of the following: commit 1909dfed99b8815c1215c709efcae77a70b52ea3 Merge:3856fda5f
2c64ab5a5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 9 16:21:38 2024 +0300 Merge branch 'master' into AGDNS-2374-slog-safesearch commit3856fda5f3
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 8 20:04:34 2024 +0300 home: imp code commitde774009aa
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Oct 7 16:41:58 2024 +0300 all: imp code commit038bae59d5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 20:24:48 2024 +0300 all: imp code commit792975e248
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 15:46:40 2024 +0300 all: slog safesearch
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package home
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
|
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
|
"github.com/AdguardTeam/golibs/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// newClientsContainer is a helper that creates a new clients container for
|
|
// tests.
|
|
func newClientsContainer(t *testing.T) (c *clientsContainer) {
|
|
t.Helper()
|
|
|
|
c = &clientsContainer{
|
|
testing: true,
|
|
}
|
|
|
|
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
|
err := c.Init(
|
|
ctx,
|
|
slogutil.NewDiscardLogger(),
|
|
nil,
|
|
client.EmptyDHCP{},
|
|
nil,
|
|
nil,
|
|
&filtering.Config{},
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return c
|
|
}
|
|
|
|
func TestClientsCustomUpstream(t *testing.T) {
|
|
clients := newClientsContainer(t)
|
|
|
|
// Add client with upstreams.
|
|
err := clients.storage.Add(&client.Persistent{
|
|
Name: "client1",
|
|
UID: client.MustNewUID(),
|
|
IPs: []netip.Addr{netip.MustParseAddr("1.1.1.1"), netip.MustParseAddr("1:2:3::4")},
|
|
Upstreams: []string{
|
|
"1.1.1.1",
|
|
"[/example.org/]8.8.8.8",
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
upsConf, err := clients.UpstreamConfigByID("1.2.3.4", net.DefaultResolver)
|
|
assert.Nil(t, upsConf)
|
|
assert.NoError(t, err)
|
|
|
|
upsConf, err = clients.UpstreamConfigByID("1.1.1.1", net.DefaultResolver)
|
|
require.NotNil(t, upsConf)
|
|
assert.NoError(t, err)
|
|
}
|