config_json_test.go 2.3 KB

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