2015-11-24 21:11:48 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2022-12-22 14:21:00 +00:00
|
|
|
"time"
|
2015-11-24 21:11:48 +00:00
|
|
|
|
2019-03-29 18:47:40 +00:00
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2022-12-22 14:21:00 +00:00
|
|
|
"github.com/shoenig/test/must"
|
|
|
|
"github.com/shoenig/test/wait"
|
2015-11-24 21:11:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegionsList(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2015-11-24 21:11:48 +00:00
|
|
|
c1, s1 := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
|
|
|
c.Region = "regionA"
|
|
|
|
})
|
|
|
|
defer s1.Stop()
|
|
|
|
|
|
|
|
c2, s2 := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
|
|
|
c.Region = "regionB"
|
|
|
|
})
|
|
|
|
defer s2.Stop()
|
|
|
|
|
|
|
|
// Join the servers
|
2022-12-22 14:21:00 +00:00
|
|
|
_, err := c2.Agent().Join(s1.SerfAddr)
|
|
|
|
must.NoError(t, err)
|
2015-11-24 21:11:48 +00:00
|
|
|
|
2022-12-22 14:21:00 +00:00
|
|
|
f := func() error {
|
2015-11-24 21:11:48 +00:00
|
|
|
regions, err := c1.Regions().List()
|
|
|
|
if err != nil {
|
2022-12-22 14:21:00 +00:00
|
|
|
return fmt.Errorf("failed to get regions: %w", err)
|
2015-11-24 21:11:48 +00:00
|
|
|
}
|
|
|
|
if n := len(regions); n != 2 {
|
2022-12-22 14:21:00 +00:00
|
|
|
return fmt.Errorf("expected 2 regions, got %d", n)
|
2015-11-24 21:11:48 +00:00
|
|
|
}
|
2022-12-22 14:21:00 +00:00
|
|
|
if regions[0] != "regionA" {
|
|
|
|
return fmt.Errorf("unexpected first region, got: %s", regions[0])
|
2015-11-24 21:11:48 +00:00
|
|
|
}
|
2022-12-22 14:21:00 +00:00
|
|
|
if regions[1] != "regionB" {
|
|
|
|
return fmt.Errorf("unexpected second region, got: %s", regions[1])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
must.Wait(t, wait.InitialSuccess(
|
|
|
|
wait.ErrorFunc(f),
|
|
|
|
wait.Timeout(10*time.Second),
|
|
|
|
wait.Gap(1*time.Second),
|
|
|
|
))
|
2015-11-24 21:11:48 +00:00
|
|
|
}
|