Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // Validate the single loadbalance.Selector.
  2. func TestSelectFrom(t *testing.T) {
  3. cases := []struct {
  4. hosts []string
  5. }{
  6. {}, // 0
  7. {[]string{}}, // 1
  8. {[]string{"a"}}, // 2
  9. {[]string{"a", "b"}}, // 3
  10. }
  11. for i, test := range cases {
  12. a := SelectFrom(test.hosts...)
  13.  
  14. // Select returns the first host each time,
  15. // or empty if no hosts are defined.
  16. var expect string
  17. if len(test.hosts) > 0 {
  18. expect = test.hosts[0]
  19. }
  20.  
  21. // 3 loops all return the same value
  22. for j := 0; j < 3; j++ {
  23. if got := a.Select(nil); got != expect {
  24. t.Errorf("[%d.%d] expected %s got %s", i, j, expect, got)
  25. }
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment