gopkg.in/hashicorp/nomad.v0@v0.11.8/nomad/regions_endpoint_test.go (about)

     1  package nomad
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
     8  	"github.com/hashicorp/nomad/nomad/structs"
     9  	"github.com/hashicorp/nomad/testutil"
    10  )
    11  
    12  func TestRegionList(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	// Make the servers
    16  	s1, cleanupS1 := TestServer(t, func(c *Config) {
    17  		c.Region = "region1"
    18  	})
    19  	defer cleanupS1()
    20  	codec := rpcClient(t, s1)
    21  
    22  	s2, cleanupS2 := TestServer(t, func(c *Config) {
    23  		c.Region = "region2"
    24  	})
    25  	defer cleanupS2()
    26  
    27  	// Join the servers
    28  	s2Addr := fmt.Sprintf("127.0.0.1:%d",
    29  		s2.config.SerfConfig.MemberlistConfig.BindPort)
    30  	if n, err := s1.Join([]string{s2Addr}); err != nil || n != 1 {
    31  		t.Fatalf("Failed joining: %v (%d joined)", err, n)
    32  	}
    33  
    34  	// Query the regions list
    35  	testutil.WaitForResult(func() (bool, error) {
    36  		var arg structs.GenericRequest
    37  		var out []string
    38  		if err := msgpackrpc.CallWithCodec(codec, "Region.List", &arg, &out); err != nil {
    39  			t.Fatalf("err: %v", err)
    40  		}
    41  		if len(out) != 2 || out[0] != "region1" || out[1] != "region2" {
    42  			t.Fatalf("unexpected regions: %v", out)
    43  		}
    44  		return true, nil
    45  	}, func(err error) {
    46  		t.Fatalf("err: %v", err)
    47  	})
    48  }