config_json_test.go 726 B

1234567891011121314151617181920212223242526272829
  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. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func TestConfigParsing(t *testing.T) {
  12. v2testing.Current(t)
  13. rawJson := `{
  14. "servers": ["8.8.8.8"]
  15. }`
  16. config := new(Config)
  17. err := json.Unmarshal([]byte(rawJson), config)
  18. assert.Error(err).IsNil()
  19. assert.Int(len(config.NameServers)).Equals(1)
  20. assert.Destination(config.NameServers[0]).IsUDP()
  21. assert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
  22. assert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
  23. }