-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_json_test.go
81 lines (61 loc) · 2.32 KB
/
config_json_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// +build json
package core_test
import (
"encoding/json"
"io"
"os"
"path/filepath"
"testing"
. "v2ray.com/core"
"v2ray.com/core/testing/assert"
)
func OpenFile(file string, assert *assert.Assert) io.Reader {
input, err := os.Open(file)
assert.Error(err).IsNil()
return input
}
func TestClientSampleConfig(t *testing.T) {
assert := assert.On(t)
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_socks_vmess.json"), assert))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Port(pointConfig.InboundConfig.Port).IsValid()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.String(pointConfig.InboundConfig.Protocol).Equals("socks")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.String(pointConfig.OutboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
func TestServerSampleConfig(t *testing.T) {
assert := assert.On(t)
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_vmess_freedom.json"), assert))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Port(pointConfig.InboundConfig.Port).IsValid()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
func TestDefaultValueOfRandomAllocation(t *testing.T) {
assert := assert.On(t)
rawJson := `{
"protocol": "vmess",
"port": 1,
"settings": {},
"allocate": {
"strategy": "random"
}
}`
inboundDetourConfig := new(InboundDetourConfig)
err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
assert.Error(err).IsNil()
assert.String(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
}