github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/nomad/regions_endpoint_test.go (about) 1 package nomad 2 3 import ( 4 "fmt" 5 "testing" 6 7 "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 // Make the servers 15 s1 := TestServer(t, func(c *Config) { 16 c.Region = "region1" 17 }) 18 defer s1.Shutdown() 19 codec := rpcClient(t, s1) 20 21 s2 := TestServer(t, func(c *Config) { 22 c.Region = "region2" 23 }) 24 defer s2.Shutdown() 25 26 // Join the servers 27 s2Addr := fmt.Sprintf("127.0.0.1:%d", 28 s2.config.SerfConfig.MemberlistConfig.BindPort) 29 if n, err := s1.Join([]string{s2Addr}); err != nil || n != 1 { 30 t.Fatalf("Failed joining: %v (%d joined)", err, n) 31 } 32 33 // Query the regions list 34 testutil.WaitForResult(func() (bool, error) { 35 var arg structs.GenericRequest 36 var out []string 37 if err := msgpackrpc.CallWithCodec(codec, "Region.List", &arg, &out); err != nil { 38 t.Fatalf("err: %v", err) 39 } 40 if len(out) != 2 || out[0] != "region1" || out[1] != "region2" { 41 t.Fatalf("unexpected regions: %v", out) 42 } 43 return true, nil 44 }, func(err error) { 45 t.Fatalf("err: %v", err) 46 }) 47 }