-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy_test.go
More file actions
61 lines (55 loc) · 1.66 KB
/
Copy pathproxy_test.go
File metadata and controls
61 lines (55 loc) · 1.66 KB
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
59
60
61
package proxykit_test
import (
"strings"
"testing"
"github.com/colduction/proxykit-go"
)
var _ proxykit.ProxyValidator = (*proxykit.Proxy)(nil)
func TestIsValidHostnamePort(t *testing.T) {
tests := []struct {
address string
valid bool
}{
{address: "proxy.example.com:8080", valid: true},
{address: "127.0.0.1:1", valid: true},
{address: "192.0.2.10:8080", valid: true},
{address: "[::1]:80", valid: true},
{address: "[2001:db8::1]:443", valid: true},
{address: "proxy-name:65535", valid: true},
{address: ":80", valid: true},
{address: "proxy.example.com:0", valid: false},
{address: "proxy.example.com:65536", valid: false},
{address: "proxy..example.com:80", valid: false},
{address: "proxy_example.com:80", valid: false},
{address: strings.Repeat("a", 64) + ":80", valid: false},
{address: "::1:80", valid: false},
}
for _, test := range tests {
if got := proxykit.IsValidHostnamePort(test.address); got != test.valid {
t.Errorf("IsValidHostnamePort(%q) = %v, want %v", test.address, got, test.valid)
}
}
}
func TestProxyValidatorMethods(t *testing.T) {
proxy := &proxykit.Proxy{
Scheme: proxykit.HTTP,
Host: "proxy.example.com:8080",
Username: "user",
Password: "pass",
}
if !proxy.IsValidScheme() {
t.Error("IsValidScheme() = false, want true")
}
if !proxy.IsValidHostnamePort() {
t.Error("IsValidHostnamePort() = false, want true")
}
if !proxy.IsValidCredentials() {
t.Error("IsValidCredentials() = false, want true")
}
var nilProxy *proxykit.Proxy
if nilProxy.IsValidScheme() ||
nilProxy.IsValidHostnamePort() ||
nilProxy.IsValidCredentials() {
t.Error("nil proxy validation methods must report false")
}
}