json_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package json_test
  2. import (
  3. "path/filepath"
  4. "testing"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  7. _ "github.com/v2ray/v2ray-core/proxy/dokodemo/json"
  8. _ "github.com/v2ray/v2ray-core/proxy/freedom/json"
  9. _ "github.com/v2ray/v2ray-core/proxy/socks/json"
  10. _ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
  11. "github.com/v2ray/v2ray-core/shell/point/json"
  12. v2testing "github.com/v2ray/v2ray-core/testing"
  13. "github.com/v2ray/v2ray-core/testing/assert"
  14. )
  15. func TestClientSampleConfig(t *testing.T) {
  16. v2testing.Current(t)
  17. // TODO: fix for Windows
  18. baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
  19. pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
  20. assert.Error(err).IsNil()
  21. netassert.Port(pointConfig.Port()).IsValid()
  22. assert.Pointer(pointConfig.InboundConfig()).IsNotNil()
  23. assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
  24. assert.StringLiteral(pointConfig.InboundConfig().Protocol()).Equals("socks")
  25. assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
  26. assert.StringLiteral(pointConfig.OutboundConfig().Protocol()).Equals("vmess")
  27. assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
  28. }
  29. func TestServerSampleConfig(t *testing.T) {
  30. v2testing.Current(t)
  31. // TODO: fix for Windows
  32. baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
  33. pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
  34. assert.Error(err).IsNil()
  35. assert.Uint16(pointConfig.Port().Value()).Positive()
  36. assert.Pointer(pointConfig.InboundConfig()).IsNotNil()
  37. assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
  38. assert.StringLiteral(pointConfig.InboundConfig().Protocol()).Equals("vmess")
  39. assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
  40. assert.StringLiteral(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
  41. assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
  42. }
  43. func TestDetourConfig(t *testing.T) {
  44. v2testing.Current(t)
  45. // TODO: fix for Windows
  46. baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
  47. pointConfig, err := json.LoadConfig(filepath.Join(baseDir, "vpoint_dns_detour.json"))
  48. assert.Error(err).IsNil()
  49. detours := pointConfig.InboundDetours()
  50. assert.Int(len(detours)).Equals(1)
  51. detour := detours[0]
  52. assert.StringLiteral(detour.Protocol()).Equals("dokodemo-door")
  53. netassert.Port(detour.PortRange().From()).Equals(v2net.Port(28394))
  54. netassert.Port(detour.PortRange().To()).Equals(v2net.Port(28394))
  55. assert.Pointer(detour.Settings()).IsNotNil()
  56. }