2019-03-15 08:08:33 -07:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2019-04-04 07:36:39 -07:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2020-03-31 07:05:18 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-05-28 01:44:04 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-03-30 14:55:28 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/tests"
|
2019-03-15 08:08:33 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// For https://github.com/cosmos/cosmos-sdk/issues/3899
|
|
|
|
func Test_runConfigCmdTwiceWithShorterNodeValue(t *testing.T) {
|
|
|
|
// Prepare environment
|
2020-03-30 14:55:28 -07:00
|
|
|
configHome, cleanup := tests.NewTestCaseDir(t)
|
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
2019-03-15 08:08:33 -07:00
|
|
|
_ = os.RemoveAll(filepath.Join(configHome, "config"))
|
2019-05-28 01:44:04 -07:00
|
|
|
viper.Set(flags.FlagHome, configHome)
|
2019-03-15 08:08:33 -07:00
|
|
|
|
|
|
|
// Init command config
|
|
|
|
cmd := ConfigCmd(configHome)
|
2020-03-31 07:05:18 -07:00
|
|
|
require.NotNil(t, cmd)
|
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"node", "tcp://localhost:26657"}))
|
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"node", "--get"}))
|
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"node", "tcp://local:26657"}))
|
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"node", "--get"}))
|
|
|
|
}
|
2019-03-15 08:08:33 -07:00
|
|
|
|
2020-03-31 07:05:18 -07:00
|
|
|
func TestConfigCmd_UnknownOption(t *testing.T) {
|
|
|
|
// Prepare environment
|
|
|
|
configHome, cleanup := tests.NewTestCaseDir(t)
|
|
|
|
t.Cleanup(cleanup)
|
2019-03-15 08:08:33 -07:00
|
|
|
|
2020-03-31 07:05:18 -07:00
|
|
|
_ = os.RemoveAll(filepath.Join(configHome, "config"))
|
|
|
|
viper.Set(flags.FlagHome, configHome)
|
2019-03-15 08:08:33 -07:00
|
|
|
|
2020-03-31 07:05:18 -07:00
|
|
|
// Init command config
|
|
|
|
cmd := ConfigCmd(configHome)
|
|
|
|
require.NotNil(t, cmd)
|
|
|
|
require.Error(t, cmd.RunE(cmd, []string{"invalid", "true"}), "unknown configuration key: \"invalid\"")
|
2019-03-15 08:08:33 -07:00
|
|
|
}
|
|
|
|
|
2020-03-30 14:55:28 -07:00
|
|
|
func TestConfigCmd_OfflineFlag(t *testing.T) {
|
|
|
|
// Prepare environment
|
|
|
|
configHome, cleanup := tests.NewTestCaseDir(t)
|
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
|
|
|
_ = os.RemoveAll(filepath.Join(configHome, "config"))
|
|
|
|
viper.Set(flags.FlagHome, configHome)
|
|
|
|
|
|
|
|
// Init command config
|
|
|
|
cmd := ConfigCmd(configHome)
|
|
|
|
_, out, _ := tests.ApplyMockIO(cmd)
|
2020-03-31 07:05:18 -07:00
|
|
|
require.NotNil(t, cmd)
|
2020-03-30 14:55:28 -07:00
|
|
|
|
|
|
|
viper.Set(flagGet, true)
|
2020-03-31 07:05:18 -07:00
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"offline"}))
|
|
|
|
require.Contains(t, out.String(), "false")
|
2020-03-30 14:55:28 -07:00
|
|
|
out.Reset()
|
|
|
|
|
|
|
|
viper.Set(flagGet, false)
|
2020-03-31 07:05:18 -07:00
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"offline", "true"}))
|
2020-03-30 14:55:28 -07:00
|
|
|
|
|
|
|
viper.Set(flagGet, true)
|
2020-03-31 07:05:18 -07:00
|
|
|
require.NoError(t, cmd.RunE(cmd, []string{"offline"}))
|
|
|
|
require.Contains(t, out.String(), "true")
|
2019-03-15 08:08:33 -07:00
|
|
|
}
|