1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 16:26:02 -04:00
v2fly/shell/point/config_json_test.go

83 lines
2.4 KiB
Go
Raw Normal View History

2016-01-17 15:43:10 -05:00
// +build json
package point_test
import (
2016-02-04 05:25:36 -05:00
"encoding/json"
2016-10-03 05:18:24 -04:00
"io"
2016-02-04 05:25:36 -05:00
"os"
2016-01-17 15:43:10 -05:00
"path/filepath"
"testing"
2016-08-20 14:55:45 -04:00
_ "v2ray.com/core/app/router/rules"
. "v2ray.com/core/shell/point"
2016-01-17 15:43:10 -05:00
2016-08-20 14:55:45 -04:00
"v2ray.com/core/testing/assert"
2016-01-17 15:43:10 -05:00
)
2016-10-03 05:18:24 -04:00
func OpenFile(file string, assert *assert.Assert) io.Reader {
input, err := os.Open(file)
assert.Error(err).IsNil()
return input
}
2016-01-17 15:43:10 -05:00
func TestClientSampleConfig(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-01-17 15:43:10 -05:00
2016-02-04 05:25:36 -05:00
GOPATH := os.Getenv("GOPATH")
2016-08-20 15:03:50 -04:00
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
2016-01-17 15:43:10 -05:00
2016-10-03 05:18:24 -04:00
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_socks_vmess.json"), assert))
2016-01-17 15:43:10 -05:00
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
2016-06-03 18:38:22 -04:00
assert.Port(pointConfig.InboundConfig.Port).IsValid()
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
2016-05-24 15:55:46 -04:00
assert.String(pointConfig.InboundConfig.Protocol).Equals("socks")
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
2016-05-24 15:55:46 -04:00
assert.String(pointConfig.OutboundConfig.Protocol).Equals("vmess")
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
func TestServerSampleConfig(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-01-17 15:43:10 -05:00
2016-02-04 05:25:36 -05:00
GOPATH := os.Getenv("GOPATH")
2016-08-20 15:03:50 -04:00
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
2016-01-17 15:43:10 -05:00
2016-10-03 05:18:24 -04:00
pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_vmess_freedom.json"), assert))
2016-01-17 15:43:10 -05:00
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
2016-06-03 18:38:22 -04:00
assert.Port(pointConfig.InboundConfig.Port).IsValid()
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
2016-05-24 15:55:46 -04:00
assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
2016-05-24 15:55:46 -04:00
assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
2016-01-17 15:43:10 -05:00
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
2016-02-04 05:25:36 -05:00
func TestDefaultValueOfRandomAllocation(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-04 05:25:36 -05:00
rawJson := `{
"protocol": "vmess",
"port": 1,
"settings": {},
"allocate": {
"strategy": "random"
}
}`
inboundDetourConfig := new(InboundDetourConfig)
err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
assert.Error(err).IsNil()
2016-05-24 15:55:46 -04:00
assert.String(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
2016-02-04 05:25:36 -05:00
assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
}