mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-30 02:28:16 +03:00
e529d29e8a
Squashed commit of the following: commit e8e6dba18b8f44392bd88999e481723a00aa3042 Merge:929283702
41cce6259
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 22 13:46:26 2024 +0300 Merge branch 'master' into AGDNS-2374-slog-client commit929283702a
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 15 14:30:00 2024 +0300 client: imp tests commitf29d8edb89
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Oct 14 15:03:08 2024 +0300 client: imp docs commit0b4311ac26
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Oct 11 19:12:50 2024 +0300 all: imp code commit1ad99ee3cb
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 10 20:59:46 2024 +0300 all: slog client
64 lines
1.4 KiB
Go
64 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)
|
|
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
|
|
|
// Add client with upstreams.
|
|
err := clients.storage.Add(ctx, &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)
|
|
}
|