json_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package json_test
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/config"
  6. "github.com/v2ray/v2ray-core/config/json"
  7. _ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
  8. _ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
  9. _ "github.com/v2ray/v2ray-core/proxy/vmess/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(config.TypeInbound)).IsNotNil()
  23. assert.String(pointConfig.OutboundConfig().Protocol()).Equals("vmess")
  24. assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).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(config.TypeInbound)).IsNotNil()
  37. assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
  38. assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
  39. }