-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathparse_test.go
51 lines (49 loc) · 840 Bytes
/
parse_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
package socks
import (
"reflect"
"testing"
"time"
)
func TestParse(t *testing.T) {
t.Parallel()
testcases := []struct {
name string
uri string
cfg config
}{
{
name: "full config",
uri: "socks5://u1:[email protected]:8080?timeout=2s",
cfg: config{
Proto: SOCKS5,
Auth: &auth{
Username: "u1",
Password: "p1",
},
Host: "127.0.0.1:8080",
Timeout: 2 * time.Second,
},
},
{
name: "simple socks5",
uri: "socks5://127.0.0.1:8080",
cfg: config{
Proto: SOCKS5,
Host: "127.0.0.1:8080",
},
},
}
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
cfg, err := parse(tc.uri)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(cfg, &tc.cfg) {
t.Fatalf("expect %v got %v", tc.cfg, cfg)
}
})
}
}