config_json_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // +build json
  2. package point_test
  3. import (
  4. "encoding/json"
  5. "io"
  6. "os"
  7. "path/filepath"
  8. "testing"
  9. _ "v2ray.com/core/app/router/rules"
  10. . "v2ray.com/core/shell/point"
  11. "v2ray.com/core/testing/assert"
  12. )
  13. func OpenFile(file string, assert *assert.Assert) io.Reader {
  14. input, err := os.Open(file)
  15. assert.Error(err).IsNil()
  16. return input
  17. }
  18. func TestClientSampleConfig(t *testing.T) {
  19. assert := assert.On(t)
  20. GOPATH := os.Getenv("GOPATH")
  21. baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
  22. pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_socks_vmess.json"), assert))
  23. assert.Error(err).IsNil()
  24. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  25. assert.Port(pointConfig.InboundConfig.Port).IsValid()
  26. assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
  27. assert.String(pointConfig.InboundConfig.Protocol).Equals("socks")
  28. assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
  29. assert.String(pointConfig.OutboundConfig.Protocol).Equals("vmess")
  30. assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
  31. }
  32. func TestServerSampleConfig(t *testing.T) {
  33. assert := assert.On(t)
  34. GOPATH := os.Getenv("GOPATH")
  35. baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
  36. pointConfig, err := LoadConfig(OpenFile(filepath.Join(baseDir, "vpoint_vmess_freedom.json"), assert))
  37. assert.Error(err).IsNil()
  38. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  39. assert.Port(pointConfig.InboundConfig.Port).IsValid()
  40. assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
  41. assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
  42. assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
  43. assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
  44. assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
  45. }
  46. func TestDefaultValueOfRandomAllocation(t *testing.T) {
  47. assert := assert.On(t)
  48. rawJson := `{
  49. "protocol": "vmess",
  50. "port": 1,
  51. "settings": {},
  52. "allocate": {
  53. "strategy": "random"
  54. }
  55. }`
  56. inboundDetourConfig := new(InboundDetourConfig)
  57. err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
  58. assert.Error(err).IsNil()
  59. assert.String(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
  60. assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
  61. assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
  62. }