ring_test.go 936 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gocql
  2. import (
  3. "net"
  4. "testing"
  5. )
  6. func TestRing_AddHostIfMissing_Missing(t *testing.T) {
  7. ring := &ring{}
  8. host := &HostInfo{peer: net.IPv4(1, 1, 1, 1)}
  9. h1, ok := ring.addHostIfMissing(host)
  10. if ok {
  11. t.Fatal("host was reported as already existing")
  12. } else if !h1.Equal(host) {
  13. t.Fatalf("hosts not equal that are returned %v != %v", h1, host)
  14. } else if h1 != host {
  15. t.Fatalf("returned host same pointer: %p != %p", h1, host)
  16. }
  17. }
  18. func TestRing_AddHostIfMissing_Existing(t *testing.T) {
  19. ring := &ring{}
  20. host := &HostInfo{peer: net.IPv4(1, 1, 1, 1)}
  21. ring.addHostIfMissing(host)
  22. h2 := &HostInfo{peer: net.IPv4(1, 1, 1, 1)}
  23. h1, ok := ring.addHostIfMissing(h2)
  24. if !ok {
  25. t.Fatal("host was not reported as already existing")
  26. } else if !h1.Equal(host) {
  27. t.Fatalf("hosts not equal that are returned %v != %v", h1, host)
  28. } else if h1 != host {
  29. t.Fatalf("returned host same pointer: %p != %p", h1, host)
  30. }
  31. }