json_test.go 2.4 KB

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