-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
dns_test.go
58 lines (51 loc) · 1.52 KB
/
dns_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Roman Atachiants and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
package address
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestResolve(t *testing.T) {
tests := []struct {
addr string
err bool
expect string
}{
{addr: "", err: true},
{addr: "https://google.com"},
{addr: "google.com"},
{addr: "google.com/1234/sds"},
{addr: "https://127.0.0.1", expect: "127.0.0.1:80"},
{addr: "https://4987e9gs99sxdg8e8e7tgwe5.boomshouldnotwork", err: true},
{addr: "127.0.0.1", expect: "127.0.0.1:80"},
{addr: "2001:db8::68", expect: "[2001:db8::68]:80"},
{addr: "192.0.2.1", expect: "192.0.2.1:80"},
{addr: "127.0.0.1:22", expect: "127.0.0.1:22"},
{addr: "127.0.0.1:8xx0", err: true},
{addr: "tcp://127.0.0.1:8000", expect: "127.0.0.1:8000"},
{addr: "https://gooo:oogle.com", err: true},
{addr: "https://google.com:xxx", err: true},
{addr: "https-----:// ://--", err: true},
{addr: "::"},
{addr: ":::", err: true},
{addr: "::::::::", err: true},
}
/*{url: "http://google.com/123", ok: true},
{url: "google.com/123", ok: false},
{url: "235235", ok: false},
{url: "::", ok: false},
*/
for _, tc := range tests {
t.Run(tc.addr, func(*testing.T) {
println("resolving " + tc.addr)
addr, err := Resolve(tc.addr, 80)
assert.Equal(t, tc.err, err != nil)
if err != nil {
println(err.Error())
}
if len(tc.expect) > 0 {
assert.Equal(t, tc.expect, addr[0].String())
}
})
}
}