dns_test.go 785 B

1234567891011121314151617181920212223242526272829303132
  1. package command_test
  2. import (
  3. "testing"
  4. "github.com/v2ray/v2ray-core/common/alloc"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  7. . "github.com/v2ray/v2ray-core/proxy/vmess/command"
  8. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func TestCacheDnsIPv4(t *testing.T) {
  12. v2testing.Current(t)
  13. cd := &CacheDns{
  14. Address: v2net.IPAddress([]byte{1, 2, 3, 4}),
  15. }
  16. buffer := alloc.NewBuffer().Clear()
  17. defer buffer.Release()
  18. nBytes, err := cd.Marshal(buffer)
  19. assert.Error(err).IsNil()
  20. assert.Int(nBytes).Equals(buffer.Len())
  21. cd2 := &CacheDns{}
  22. err = cd2.Unmarshal(buffer.Value)
  23. assert.Error(err).IsNil()
  24. netassert.Address(cd.Address).Equals(cd2.Address)
  25. }