2022-10-05 06:44:10 +00:00
|
|
|
package options_test
|
2020-09-25 16:32:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"testing"
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/app"
|
2020-09-25 16:32:53 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testcli"
|
2020-09-25 16:32:53 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetRPCClient(t *testing.T) {
|
2022-10-05 06:44:10 +00:00
|
|
|
e := testcli.NewExecutor(t, true)
|
2020-09-25 16:32:53 +00:00
|
|
|
|
|
|
|
t.Run("no endpoint", func(t *testing.T) {
|
|
|
|
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
2022-10-05 06:44:10 +00:00
|
|
|
ctx := cli.NewContext(app.New(), set, nil)
|
2020-09-25 16:32:53 +00:00
|
|
|
gctx, _ := options.GetTimeoutContext(ctx)
|
|
|
|
_, ec := options.GetRPCClient(gctx, ctx)
|
|
|
|
require.Equal(t, 1, ec.ExitCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
|
|
|
set.String(options.RPCEndpointFlag, "http://"+e.RPC.Addr, "")
|
2022-10-05 06:44:10 +00:00
|
|
|
ctx := cli.NewContext(app.New(), set, nil)
|
2020-09-25 16:32:53 +00:00
|
|
|
gctx, _ := options.GetTimeoutContext(ctx)
|
|
|
|
_, ec := options.GetRPCClient(gctx, ctx)
|
|
|
|
require.Nil(t, ec)
|
|
|
|
})
|
|
|
|
}
|