config_json_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  10. . "github.com/v2ray/v2ray-core/shell/point"
  11. v2testing "github.com/v2ray/v2ray-core/testing"
  12. "github.com/v2ray/v2ray-core/testing/assert"
  13. )
  14. func TestClientSampleConfig(t *testing.T) {
  15. v2testing.Current(t)
  16. GOPATH := os.Getenv("GOPATH")
  17. baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
  18. pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
  19. assert.Error(err).IsNil()
  20. netassert.Port(pointConfig.Port).IsValid()
  21. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  22. assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
  23. assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("socks")
  24. assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
  25. assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("vmess")
  26. assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
  27. }
  28. func TestServerSampleConfig(t *testing.T) {
  29. v2testing.Current(t)
  30. GOPATH := os.Getenv("GOPATH")
  31. baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
  32. pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
  33. assert.Error(err).IsNil()
  34. netassert.Port(pointConfig.Port).IsValid()
  35. assert.Pointer(pointConfig.InboundConfig).IsNotNil()
  36. assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
  37. assert.StringLiteral(pointConfig.InboundConfig.Protocol).Equals("vmess")
  38. assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
  39. assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("freedom")
  40. assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
  41. }
  42. func TestDefaultValueOfRandomAllocation(t *testing.T) {
  43. v2testing.Current(t)
  44. rawJson := `{
  45. "protocol": "vmess",
  46. "port": 1,
  47. "settings": {},
  48. "allocate": {
  49. "strategy": "random"
  50. }
  51. }`
  52. inboundDetourConfig := new(InboundDetourConfig)
  53. err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
  54. assert.Error(err).IsNil()
  55. assert.StringLiteral(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
  56. assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
  57. assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
  58. }