mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-17 05:01:35 +03:00
91dee0986b
Merge in DNS/adguard-home from upd-sorting to master Squashed commit of the following: commit 7bd21de65c50168d5ad83ff46e63f4cbca365d23 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Feb 21 10:57:17 2023 +0300 all: upd sorting, go-lint
54 lines
908 B
Go
54 lines
908 B
Go
package dnsforward
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/exp/slices"
|
|
)
|
|
|
|
func TestAnyNameMatches(t *testing.T) {
|
|
dnsNames := []string{"host1", "*.host2", "1.2.3.4"}
|
|
slices.Sort(dnsNames)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
dnsName string
|
|
want bool
|
|
}{{
|
|
name: "match",
|
|
dnsName: "host1",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "a.host2",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "b.a.host2",
|
|
want: true,
|
|
}, {
|
|
name: "match",
|
|
dnsName: "1.2.3.4",
|
|
want: true,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "host2",
|
|
want: false,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "",
|
|
want: false,
|
|
}, {
|
|
name: "mismatch",
|
|
dnsName: "*.host2",
|
|
want: false,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
assert.Equal(t, tc.want, anyNameMatches(dnsNames, tc.dnsName))
|
|
})
|
|
}
|
|
}
|