2015-10-16 04:42:09 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCoordinate_Datacenters(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
coordinate := c.Coordinate()
|
|
|
|
|
2017-03-23 22:27:16 +00:00
|
|
|
if err := testutil.WaitForResult(func() (bool, error) {
|
2015-10-16 04:42:09 +00:00
|
|
|
datacenters, err := coordinate.Datacenters()
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(datacenters) == 0 {
|
|
|
|
return false, fmt.Errorf("Bad: %v", datacenters)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
2017-03-23 22:27:16 +00:00
|
|
|
}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-10-16 04:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCoordinate_Nodes(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
coordinate := c.Coordinate()
|
|
|
|
|
2017-03-23 22:27:16 +00:00
|
|
|
if err := testutil.WaitForResult(func() (bool, error) {
|
2015-10-16 04:42:09 +00:00
|
|
|
_, _, err := coordinate.Nodes(nil)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's not a good way to populate coordinates without
|
|
|
|
// waiting for them to calculate and update, so the best
|
|
|
|
// we can do is call the endpoint and make sure we don't
|
|
|
|
// get an error.
|
|
|
|
return true, nil
|
2017-03-23 22:27:16 +00:00
|
|
|
}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-10-16 04:42:09 +00:00
|
|
|
}
|