forked from folbricht/routedns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_default_ports_test.go
36 lines (32 loc) · 1.12 KB
/
static_default_ports_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package rdns
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDefaultPort(t *testing.T) {
tests := []struct {
address string
defaultPort string
expected string
}{
{"", DoTPort, ":853"},
{"localhost", DoTPort, "localhost:853"},
{"localhost:123", DoTPort, "localhost:123"},
{"1.2.3.4", DoTPort, "1.2.3.4:853"},
{"1.2.3.4:123", DoTPort, "1.2.3.4:123"},
{"https://localhost", DoHPort, "https://localhost:443"},
{"https://localhost:123", DoHPort, "https://localhost:123"},
{"https://localhost:123/path", DoHPort, "https://localhost:123/path"},
{"https://localhost/dns-query{?dns}", DoHPort, "https://localhost:443/dns-query{?dns}"},
{"https://1.1.1.1:443/dns-query{?dns}", DoHPort, "https://1.1.1.1:443/dns-query{?dns}"},
// Invalid endpoints should ideally not be changed
{"localhost:", DoTPort, "localhost:"},
{"localhost::123", DoTPort, "localhost::123"},
{"127.0.0.1:", DoTPort, "127.0.0.1:"},
{"127.0.0.1::123", DoTPort, "127.0.0.1::123"},
}
for _, test := range tests {
out := AddressWithDefault(test.address, test.defaultPort)
require.Equal(t, test.expected, out)
}
}