mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-19 21:41:56 +03:00
d40de33316
Squashed commit of the following: commit3191224d6d
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 18:20:04 2024 +0300 client: imp tests commit6cc4ed53a2
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 18:04:36 2024 +0300 client: imp code commit79272b299a
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 16:10:06 2024 +0300 all: imp code commit0a001fffbe
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 20:05:47 2024 +0300 all: imp tests commit80f7e98d30
Merge:df7492e9d
e338214ad
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 19:10:13 2024 +0300 Merge branch 'master' into AG-27492-client-storage-runtime-sources commitdf7492e9de
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 19:06:37 2024 +0300 all: imp code commit23896ae5a6
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 19 21:04:34 2024 +0300 client: fix typo commitba0ba2478c
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 19 21:02:13 2024 +0300 all: imp code commitf7315be742
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 12 14:35:38 2024 +0300 home: imp code commitf63d0e80fb
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 12 14:15:49 2024 +0300 all: imp code commit9feda414b6
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 10 17:53:42 2024 +0300 all: imp code commitfafd7cbb52
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Sep 9 21:13:05 2024 +0300 all: imp code commit2d2b8e0216
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 5 20:55:10 2024 +0300 client: add tests commit4d394e6f21
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 29 20:40:38 2024 +0300 all: client storage runtime sources
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package home
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
|
"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,
|
|
}
|
|
|
|
require.NoError(t, c.Init(nil, client.EmptyDHCP{}, nil, nil, &filtering.Config{}))
|
|
|
|
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)
|
|
}
|