ring_test.go 885 B

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