Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbono3 committed Apr 12, 2021
1 parent b97460c commit c953f78
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
)

const (
nodeEnv = "NODE"
testNode1 = "http://localhost:1"
testNode2 = "http://localhost:2"
)

// initClientContext initiates client Context for tests
func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
home := t.TempDir()
clientCtx := client.Context{}.
WithHomeDir(home).
WithViper()
WithViper("")

clientCtx.Viper.BindEnv(nodeEnv)
if envVar != "" {
Expand Down Expand Up @@ -81,25 +83,25 @@ func TestConfigCmdEnvFlag(t *testing.T) {
for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
clientCtx, cleanup := initClientContext(t, tc.envVar)
clientCtx, cleanup := initClientContext(t, tc.envVar)
defer func() {
if tc.envVar != "" {
os.Unsetenv(nodeEnv)
}
cleanup()
}()
/*
env var is set with a flag
env var is set with a flag
NODE=http://localhost:1 ./build/simd q staking validators --node http://localhost:2
Error: post failed: Post "http://localhost:2": dial tcp 127.0.0.1:2: connect: connection refused
NODE=http://localhost:1 ./build/simd q staking validators --node http://localhost:2
Error: post failed: Post "http://localhost:2": dial tcp 127.0.0.1:2: connect: connection refused
We dial http://localhost:2 cause a flag has the higher priority than env variable.
We dial http://localhost:2 cause a flag has the higher priority than env variable.
*/
cmd := cli.GetQueryCmd()
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
require.Error(t, err)
require.Contains(t, err.Error(), tc.expNode, "Output does not contain expected Node")
require.Contains(t, err.Error(), tc.expNode, "Output does not contain expected Node")
})
}
}

0 comments on commit c953f78

Please sign in to comment.