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