json_test.go 2.6 KB

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