config_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package json
  2. import (
  3. "encoding/json"
  4. "net"
  5. "testing"
  6. "github.com/v2ray/v2ray-core/proxy/common/config"
  7. jsonconfig "github.com/v2ray/v2ray-core/proxy/common/config/json"
  8. "github.com/v2ray/v2ray-core/testing/unit"
  9. )
  10. func TestAccountMapParsing(t *testing.T) {
  11. assert := unit.Assert(t)
  12. var accountMap SocksAccountMap
  13. err := json.Unmarshal([]byte("[{\"user\": \"a\", \"pass\":\"b\"}, {\"user\": \"c\", \"pass\":\"d\"}]"), &accountMap)
  14. assert.Error(err).IsNil()
  15. value, found := accountMap["a"]
  16. assert.Bool(found).IsTrue()
  17. assert.String(value).Equals("b")
  18. value, found = accountMap["c"]
  19. assert.Bool(found).IsTrue()
  20. assert.String(value).Equals("d")
  21. }
  22. func TestDefaultIPAddress(t *testing.T) {
  23. assert := unit.Assert(t)
  24. socksConfig := jsonconfig.CreateConfig("socks", config.TypeInbound).(*SocksConfig)
  25. assert.String(socksConfig.IP().String()).Equals("127.0.0.1")
  26. }
  27. func TestIPAddressParsing(t *testing.T) {
  28. assert := unit.Assert(t)
  29. var ipAddress IPAddress
  30. err := json.Unmarshal([]byte("\"1.2.3.4\""), &ipAddress)
  31. assert.Error(err).IsNil()
  32. assert.String(net.IP(ipAddress).String()).Equals("1.2.3.4")
  33. }