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

76 lines
2.2 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"
"os"
2016-01-17 15:43:10 -05:00
"path/filepath"
"testing"
_ "github.com/v2ray/v2ray-core/app/router/rules"
. "github.com/v2ray/v2ray-core/shell/point"
"github.com/v2ray/v2ray-core/testing/assert"
)
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")
baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
2016-01-17 15:43:10 -05:00
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
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")
baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
2016-01-17 15:43:10 -05:00
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
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)
}