control_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package gocql
  2. import (
  3. "net"
  4. "testing"
  5. )
  6. func TestHostInfo_Lookup(t *testing.T) {
  7. hostLookupPreferV4 = true
  8. defer func() { hostLookupPreferV4 = false }()
  9. tests := [...]struct {
  10. addr string
  11. ip net.IP
  12. }{
  13. {"127.0.0.1", net.IPv4(127, 0, 0, 1)},
  14. {"localhost", net.IPv4(127, 0, 0, 1)}, // TODO: this may be host dependant
  15. }
  16. for i, test := range tests {
  17. hosts, err := hostInfo(test.addr, 1)
  18. if err != nil {
  19. t.Errorf("%d: %v", i, err)
  20. continue
  21. }
  22. host := hosts[0]
  23. if !host.ConnectAddress().Equal(test.ip) {
  24. t.Errorf("expected ip %v got %v for addr %q", test.ip, host.ConnectAddress(), test.addr)
  25. }
  26. }
  27. }
  28. func TestParseProtocol(t *testing.T) {
  29. tests := [...]struct {
  30. err error
  31. proto int
  32. }{
  33. {
  34. err: &protocolError{
  35. frame: errorFrame{
  36. code: 0x10,
  37. message: "Invalid or unsupported protocol version (5); the lowest supported version is 3 and the greatest is 4",
  38. },
  39. },
  40. proto: 4,
  41. },
  42. {
  43. err: &protocolError{
  44. frame: errorFrame{
  45. frameHeader: frameHeader{
  46. version: 0x83,
  47. },
  48. code: 0x10,
  49. message: "Invalid or unsupported protocol version: 5",
  50. },
  51. },
  52. proto: 3,
  53. },
  54. }
  55. for i, test := range tests {
  56. if proto := parseProtocolFromError(test.err); proto != test.proto {
  57. t.Errorf("%d: exepcted proto %d got %d", i, test.proto, proto)
  58. }
  59. }
  60. }