json_test.go 2.5 KB

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