AdGuardHome/internal/home/clients_internal_test.go

51 lines
1.2 KiB
Go
Raw Normal View History

package home
import (
"net"
2022-11-02 13:18:02 +00:00
"net/netip"
"testing"
2023-09-07 15:13:48 +01:00
"github.com/AdguardTeam/AdGuardHome/internal/client"
2023-04-12 12:48:42 +01:00
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2023-04-12 12:48:42 +01:00
// newClientsContainer is a helper that creates a new clients container for
// tests.
2023-07-03 12:10:40 +01:00
func newClientsContainer(t *testing.T) (c *clientsContainer) {
2023-09-07 15:13:48 +01:00
t.Helper()
2023-04-12 12:48:42 +01:00
c = &clientsContainer{
testing: true,
}
2024-09-30 18:17:20 +01:00
require.NoError(t, c.Init(nil, client.EmptyDHCP{}, nil, nil, &filtering.Config{}))
2023-04-12 12:48:42 +01:00
return c
}
func TestClientsCustomUpstream(t *testing.T) {
2023-07-03 12:10:40 +01:00
clients := newClientsContainer(t)
// Add client with upstreams.
2024-07-03 13:38:37 +01:00
err := clients.storage.Add(&client.Persistent{
Name: "client1",
2024-03-12 14:45:11 +00:00
UID: client.MustNewUID(),
2024-01-30 15:43:51 +00:00
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)
}