vmess_test.go 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package conf_test
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "v2ray.com/core/common/protocol"
  6. "v2ray.com/core/proxy/vmess"
  7. "v2ray.com/core/proxy/vmess/outbound"
  8. "v2ray.com/core/testing/assert"
  9. . "v2ray.com/core/tools/conf"
  10. )
  11. func TestConfigTargetParsing(t *testing.T) {
  12. assert := assert.On(t)
  13. rawJson := `{
  14. "vnext": [{
  15. "address": "127.0.0.1",
  16. "port": 80,
  17. "users": [
  18. {
  19. "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
  20. "email": "love@v2ray.com",
  21. "level": 255
  22. }
  23. ]
  24. }]
  25. }`
  26. rawConfig := new(VMessOutboundConfig)
  27. err := json.Unmarshal([]byte(rawJson), &rawConfig)
  28. assert.Error(err).IsNil()
  29. ts, err := rawConfig.Build()
  30. assert.Error(err).IsNil()
  31. iConfig, err := ts.GetInstance()
  32. assert.Error(err).IsNil()
  33. config := iConfig.(*outbound.Config)
  34. specPB := config.Receiver[0]
  35. spec := protocol.NewServerSpecFromPB(vmess.NewAccount, *specPB)
  36. assert.Destination(spec.Destination()).EqualsString("tcp:127.0.0.1:80")
  37. }