github.com/djenriquez/nomad-1@v0.8.1/client/rpc_test.go (about) 1 package client 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/hashicorp/nomad/client/config" 8 "github.com/hashicorp/nomad/nomad" 9 "github.com/hashicorp/nomad/nomad/structs" 10 sconfig "github.com/hashicorp/nomad/nomad/structs/config" 11 "github.com/hashicorp/nomad/testutil" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestRpc_streamingRpcConn_badEndpoint(t *testing.T) { 16 t.Parallel() 17 require := require.New(t) 18 s1 := nomad.TestServer(t, nil) 19 defer s1.Shutdown() 20 testutil.WaitForLeader(t, s1.RPC) 21 22 c := TestClient(t, func(c *config.Config) { 23 c.Servers = []string{s1.GetConfig().RPCAddr.String()} 24 }) 25 defer c.Shutdown() 26 27 // Wait for the client to connect 28 testutil.WaitForResult(func() (bool, error) { 29 node, err := s1.State().NodeByID(nil, c.NodeID()) 30 if err != nil { 31 return false, err 32 } 33 if node == nil { 34 return false, errors.New("no node") 35 } 36 37 return node.Status == structs.NodeStatusReady, errors.New("wrong status") 38 }, func(err error) { 39 t.Fatalf("should have a clients") 40 }) 41 42 // Get the server 43 server := c.servers.FindServer() 44 require.NotNil(server) 45 46 conn, err := c.streamingRpcConn(server, "Bogus") 47 require.Nil(conn) 48 require.NotNil(err) 49 require.Contains(err.Error(), "Unknown rpc method: \"Bogus\"") 50 } 51 52 func TestRpc_streamingRpcConn_badEndpoint_TLS(t *testing.T) { 53 t.Parallel() 54 require := require.New(t) 55 56 const ( 57 cafile = "../helper/tlsutil/testdata/ca.pem" 58 foocert = "../helper/tlsutil/testdata/nomad-foo.pem" 59 fookey = "../helper/tlsutil/testdata/nomad-foo-key.pem" 60 ) 61 62 s1 := nomad.TestServer(t, func(c *nomad.Config) { 63 c.Region = "regionFoo" 64 c.BootstrapExpect = 1 65 c.DevDisableBootstrap = true 66 c.TLSConfig = &sconfig.TLSConfig{ 67 EnableHTTP: true, 68 EnableRPC: true, 69 VerifyServerHostname: true, 70 CAFile: cafile, 71 CertFile: foocert, 72 KeyFile: fookey, 73 } 74 }) 75 defer s1.Shutdown() 76 testutil.WaitForLeader(t, s1.RPC) 77 78 c := TestClient(t, func(c *config.Config) { 79 c.Region = "regionFoo" 80 c.Servers = []string{s1.GetConfig().RPCAddr.String()} 81 c.TLSConfig = &sconfig.TLSConfig{ 82 EnableHTTP: true, 83 EnableRPC: true, 84 VerifyServerHostname: true, 85 CAFile: cafile, 86 CertFile: foocert, 87 KeyFile: fookey, 88 } 89 }) 90 defer c.Shutdown() 91 92 // Wait for the client to connect 93 testutil.WaitForResult(func() (bool, error) { 94 node, err := s1.State().NodeByID(nil, c.NodeID()) 95 if err != nil { 96 return false, err 97 } 98 if node == nil { 99 return false, errors.New("no node") 100 } 101 102 return node.Status == structs.NodeStatusReady, errors.New("wrong status") 103 }, func(err error) { 104 t.Fatalf("should have a clients") 105 }) 106 107 // Get the server 108 server := c.servers.FindServer() 109 require.NotNil(server) 110 111 conn, err := c.streamingRpcConn(server, "Bogus") 112 require.Nil(conn) 113 require.NotNil(err) 114 require.Contains(err.Error(), "Unknown rpc method: \"Bogus\"") 115 }