config_json_test.go 802 B

123456789101112131415161718192021222324252627282930
  1. // +build json
  2. package dns_test
  3. import (
  4. "encoding/json"
  5. "testing"
  6. . "github.com/v2ray/v2ray-core/app/dns"
  7. v2net "github.com/v2ray/v2ray-core/common/net"
  8. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  9. v2testing "github.com/v2ray/v2ray-core/testing"
  10. "github.com/v2ray/v2ray-core/testing/assert"
  11. )
  12. func TestConfigParsing(t *testing.T) {
  13. v2testing.Current(t)
  14. rawJson := `{
  15. "servers": ["8.8.8.8"]
  16. }`
  17. config := new(Config)
  18. err := json.Unmarshal([]byte(rawJson), config)
  19. assert.Error(err).IsNil()
  20. assert.Int(len(config.NameServers)).Equals(1)
  21. netassert.Destination(config.NameServers[0]).IsUDP()
  22. netassert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
  23. netassert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
  24. }