config_json_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // +build json
  2. package point_test
  3. import (
  4. "encoding/json"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. _ "github.com/v2ray/v2ray-core/app/router/rules"
  9. . "github.com/v2ray/v2ray-core/shell/point"
  10. "github.com/v2ray/v2ray-core/testing/assert"
  11. )
  12. func TestClientSampleConfig(t *testing.T) {
  13. assert := assert.On(t)
  14. GOPATH := os.Getenv("GOPATH")
  15. baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config")
  16. pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
  17. assert.Error(err).IsNil()
  18. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  19. assert.Port(pointConfig.InboundConfig.Port).IsValid()
  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 := assert.On(t)
  28. GOPATH := os.Getenv("GOPATH")
  29. baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config")
  30. pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
  31. assert.Error(err).IsNil()
  32. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  33. assert.Port(pointConfig.InboundConfig.Port).IsValid()
  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 TestDefaultValueOfRandomAllocation(t *testing.T) {
  41. assert := assert.On(t)
  42. rawJson := `{
  43. "protocol": "vmess",
  44. "port": 1,
  45. "settings": {},
  46. "allocate": {
  47. "strategy": "random"
  48. }
  49. }`
  50. inboundDetourConfig := new(InboundDetourConfig)
  51. err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
  52. assert.Error(err).IsNil()
  53. assert.String(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
  54. assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
  55. assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
  56. }