-
-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathparse_test.go
More file actions
50 lines (44 loc) · 1.34 KB
/
Copy pathparse_test.go
File metadata and controls
50 lines (44 loc) · 1.34 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
package engine
import (
"strings"
"testing"
"github.com/xjasonlyu/tun2socks/v2/proxy"
)
// TestBuildProxySplit guards against regression of the netstack()
// guard that used to reject tcp-proxy/udp-proxy configurations when
// --proxy was empty. buildProxy should accept that pairing and return
// a *proxy.Split.
func TestBuildProxySplit(t *testing.T) {
p, err := buildProxy(&Key{TCPProxy: "direct://", UDPProxy: "direct://"})
if err != nil {
t.Fatalf("buildProxy split: %v", err)
}
if _, ok := p.(*proxy.Split); !ok {
t.Fatalf("buildProxy split: got %T, want *proxy.Split", p)
}
}
func TestBuildProxyEmpty(t *testing.T) {
_, err := buildProxy(&Key{})
if err == nil {
t.Fatal("buildProxy empty: expected error, got nil")
}
if !strings.Contains(err.Error(), "no proxy configured") {
t.Fatalf("buildProxy empty: unexpected error: %v", err)
}
}
func TestBuildProxyBaseOnly(t *testing.T) {
p, err := buildProxy(&Key{Proxy: "direct://"})
if err != nil {
t.Fatalf("buildProxy base-only: %v", err)
}
if _, ok := p.(*proxy.Split); ok {
t.Fatalf("buildProxy base-only: got *proxy.Split, want direct proxy")
}
}
func TestBuildProxyHalfSplit(t *testing.T) {
// udp-proxy set, tcp-proxy empty, no base -> error
_, err := buildProxy(&Key{UDPProxy: "direct://"})
if err == nil {
t.Fatal("buildProxy half-split: expected error, got nil")
}
}