open-nomad/api/regions_test.go
Jeff Mitchell 13dab7dd24
Divest api/ package of deps elsewhere in the nomad repo. (#5488)
* Divest api/ package of deps elsewhere in the nomad repo.

This will allow making api/ a module without then pulling in the
external repo, leading to a package name conflict.

This required some migration of tests to an apitests/ folder (can be
moved anywhere as it has no deps on it). It also required some
duplication of code, notably some test helpers from api/ -> apitests/
and part (but not all) of testutil/ -> api/testutil/.

Once there's more separation and an e.g. sdk/ folder those can be
removed in favor of a dep on the sdk/ folder, provided the sdk/ folder
doesn't depend on api/ or /.

* Also remove consul dep from api/ package

* Fix stupid linters

* Some restructuring
2019-03-29 14:47:40 -04:00

44 lines
924 B
Go

package api
import (
"fmt"
"testing"
"github.com/hashicorp/nomad/api/internal/testutil"
)
func TestRegionsList(t *testing.T) {
t.Parallel()
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
if _, err := c2.Agent().Join(s1.SerfAddr); err != nil {
t.Fatalf("err: %v", err)
}
// Regions returned and sorted
testutil.WaitForResult(func() (bool, error) {
regions, err := c1.Regions().List()
if err != nil {
return false, err
}
if n := len(regions); n != 2 {
return false, fmt.Errorf("expected 2 regions, got: %d", n)
}
if regions[0] != "regionA" || regions[1] != "regionB" {
return false, fmt.Errorf("bad: %#v", regions)
}
return true, nil
}, func(err error) {
t.Fatalf("err: %v", err)
})
}