diff options
author | Valery Piashchynski <[email protected]> | 2022-03-09 09:09:46 +0100 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2022-03-09 09:09:46 +0100 |
commit | ac021525b68512f2d855ec7a870a0d2086a5f318 (patch) | |
tree | 30dd607d2f8c88b34871248eeb421c0a0c1fc69b /internal/rpc/client_test.go | |
parent | 1c5a6a590832bbefb2cab99a81f413a5a0e756de (diff) |
viper auto envs and ${} syntax support for the internal RPC client
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/rpc/client_test.go')
-rw-r--r-- | internal/rpc/client_test.go | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/internal/rpc/client_test.go b/internal/rpc/client_test.go index 0744e167..42b2d87e 100644 --- a/internal/rpc/client_test.go +++ b/internal/rpc/client_test.go @@ -2,9 +2,11 @@ package rpc_test import ( "net" + "os" "testing" "github.com/roadrunner-server/roadrunner/v2/internal/rpc" + "github.com/stretchr/testify/require" "github.com/roadrunner-server/config/v2" "github.com/stretchr/testify/assert" @@ -14,22 +16,22 @@ func TestNewClient_RpcServiceDisabled(t *testing.T) { cfgPlugin := &config.Plugin{Type: "yaml", ReadInCfg: []byte{}} assert.NoError(t, cfgPlugin.Init()) - c, err := rpc.NewClient("test/config_rpc_empty.yaml") + c, err := rpc.NewClient("test/config_rpc_empty.yaml", nil) assert.Nil(t, c) - assert.EqualError(t, err, "rpc service disabled") + assert.EqualError(t, err, "rpc service not specified") } func TestNewClient_WrongRcpConfiguration(t *testing.T) { - c, err := rpc.NewClient("test/config_rpc_wrong.yaml") + c, err := rpc.NewClient("test/config_rpc_wrong.yaml", nil) assert.Nil(t, c) assert.Error(t, err) - assert.Contains(t, err.Error(), "'' expected a map, got 'string'") + assert.Contains(t, err.Error(), "invalid socket DSN") } func TestNewClient_ConnectionError(t *testing.T) { - c, err := rpc.NewClient("test/config_rpc_conn_err.yaml") + c, err := rpc.NewClient("test/config_rpc_conn_err.yaml", nil) assert.Nil(t, c) assert.Error(t, err) @@ -42,7 +44,52 @@ func TestNewClient_SuccessfullyConnected(t *testing.T) { defer func() { assert.NoError(t, l.Close()) }() - c, err := rpc.NewClient("test/config_rpc_ok.yaml") + c, err := rpc.NewClient("test/config_rpc_ok.yaml", nil) + + assert.NotNil(t, c) + assert.NoError(t, err) + + defer func() { assert.NoError(t, c.Close()) }() +} + +func TestNewClient_SuccessfullyConnectedOverride(t *testing.T) { + l, err := net.Listen("tcp", "127.0.0.1:55555") + assert.NoError(t, err) + + defer func() { assert.NoError(t, l.Close()) }() + + c, err := rpc.NewClient("test/config_rpc_empty.yaml", []string{"rpc.listen=tcp://127.0.0.1:55555"}) + + assert.NotNil(t, c) + assert.NoError(t, err) + + defer func() { assert.NoError(t, c.Close()) }() +} + +func TestNewClient_SuccessfullyConnectedEnv(t *testing.T) { + l, err := net.Listen("tcp", "127.0.0.1:55556") + assert.NoError(t, err) + + defer func() { assert.NoError(t, l.Close()) }() + + require.NoError(t, os.Setenv("RR_RPC_LISTEN", "tcp://127.0.0.1:55556")) + c, err := rpc.NewClient("test/config_rpc_ok.yaml", nil) + + assert.NotNil(t, c) + assert.NoError(t, err) + + defer func() { assert.NoError(t, c.Close()) }() +} + +// ${} syntax +func TestNewClient_SuccessfullyConnectedEnvDollarSyntax(t *testing.T) { + l, err := net.Listen("tcp", "127.0.0.1:55556") + assert.NoError(t, err) + + defer func() { assert.NoError(t, l.Close()) }() + + require.NoError(t, os.Setenv("RPC", "tcp://127.0.0.1:55556")) + c, err := rpc.NewClient("test/config_rpc_ok_env.yaml", nil) assert.NotNil(t, c) assert.NoError(t, err) |