Config file need to be truncated while rewriting.
This commit is contained in:
parent
5081c930de
commit
8d6d8adb5f
|
@ -0,0 +1 @@
|
|||
#3899 Using 'gaiacli config node' breaks ~/config/config.toml
|
|
@ -144,7 +144,7 @@ func loadConfigFile(cfgFile string) (*toml.Tree, error) {
|
|||
}
|
||||
|
||||
func saveConfigFile(cfgFile string, tree *toml.Tree) error {
|
||||
fp, err := os.OpenFile(cfgFile, os.O_WRONLY|os.O_CREATE, 0644)
|
||||
fp, err := os.OpenFile(cfgFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// For https://github.com/cosmos/cosmos-sdk/issues/3899
|
||||
func Test_runConfigCmdTwiceWithShorterNodeValue(t *testing.T) {
|
||||
// Prepare environment
|
||||
t.Parallel()
|
||||
configHome, cleanup := tmpDir(t)
|
||||
defer cleanup()
|
||||
_ = os.RemoveAll(filepath.Join(configHome, "config"))
|
||||
viper.Set(cli.HomeFlag, configHome)
|
||||
|
||||
// Init command config
|
||||
cmd := ConfigCmd(configHome)
|
||||
assert.NotNil(t, cmd)
|
||||
|
||||
err := cmd.RunE(cmd, []string{"node", "tcp://localhost:26657"})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = cmd.RunE(cmd, []string{"node", "--get"})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = cmd.RunE(cmd, []string{"node", "tcp://local:26657"})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = cmd.RunE(cmd, []string{"node", "--get"})
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func tmpDir(t *testing.T) (string, func()) {
|
||||
dir, err := ioutil.TempDir("", t.Name()+"_")
|
||||
require.NoError(t, err)
|
||||
return dir, func() { _ = os.RemoveAll(dir) }
|
||||
}
|
Loading…
Reference in New Issue