2016-10-17 12:35:13 +00:00
|
|
|
package conf_test
|
2016-07-25 14:48:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-09-24 21:11:58 +00:00
|
|
|
"v2ray.com/core/common/protocol"
|
2016-10-17 12:35:13 +00:00
|
|
|
"v2ray.com/core/proxy/vmess/outbound"
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/testing/assert"
|
2016-10-17 12:35:13 +00:00
|
|
|
. "v2ray.com/core/tools/conf"
|
2016-07-25 14:48:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigTargetParsing(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
rawJson := `{
|
|
|
|
"vnext": [{
|
|
|
|
"address": "127.0.0.1",
|
|
|
|
"port": 80,
|
|
|
|
"users": [
|
|
|
|
{
|
|
|
|
"id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
|
|
|
|
"email": "love@v2ray.com",
|
|
|
|
"level": 255
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}`
|
|
|
|
|
2016-10-17 12:35:13 +00:00
|
|
|
rawConfig := new(VMessOutboundConfig)
|
|
|
|
err := json.Unmarshal([]byte(rawJson), &rawConfig)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
ts, err := rawConfig.Build()
|
2016-07-25 14:48:09 +00:00
|
|
|
assert.Error(err).IsNil()
|
2016-10-17 12:35:13 +00:00
|
|
|
|
|
|
|
iConfig, err := ts.GetInstance()
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
config := iConfig.(*outbound.Config)
|
2016-09-24 21:11:58 +00:00
|
|
|
specPB := config.Receiver[0]
|
2016-11-02 15:41:02 +00:00
|
|
|
spec := protocol.NewServerSpecFromPB(*specPB)
|
2016-09-24 21:11:58 +00:00
|
|
|
assert.Destination(spec.Destination()).EqualsString("tcp:127.0.0.1:80")
|
2016-07-25 14:48:09 +00:00
|
|
|
}
|