Browse Source

cmd/tendermint/commands: replace $HOME/.some/test/dir with t.TempDir (#6623)

* cmd/tendermint/commands: replace $HOME/.some/test/dir with t.TempDir

* update changelog

Co-authored-by: Marko <marbar3778@yahoo.com>
pull/6629/head
Tanya Bouman 3 years ago
committed by GitHub
parent
commit
09ec247646
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -6
      cmd/tendermint/commands/root_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -131,6 +131,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [statesync] \#6587 Increase chunk priority and re-request chunks that don't arrive (@cmwaters) - [statesync] \#6587 Increase chunk priority and re-request chunks that don't arrive (@cmwaters)
- [state/privval] \#6578 No GetPubKey retry beyond the proposal/voting window (@JayT106) - [state/privval] \#6578 No GetPubKey retry beyond the proposal/voting window (@JayT106)
- [rpc] \#6615 Add TotalGasUsed to block_results response (@crypto-facs) - [rpc] \#6615 Add TotalGasUsed to block_results response (@crypto-facs)
- [cmd/tendermint/commands] \#6623 replace `$HOME/.some/test/dir` with `t.TempDir` (@tanyabouman)
### BUG FIXES ### BUG FIXES


+ 5
- 6
cmd/tendermint/commands/root_test.go View File

@ -18,10 +18,6 @@ import (
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
) )
var (
defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")
)
// clearConfig clears env vars, the given root dir, and resets viper. // clearConfig clears env vars, the given root dir, and resets viper.
func clearConfig(dir string) { func clearConfig(dir string) {
if err := os.Unsetenv("TMHOME"); err != nil { if err := os.Unsetenv("TMHOME"); err != nil {
@ -52,10 +48,10 @@ func testRootCmd() *cobra.Command {
} }
func testSetup(rootDir string, args []string, env map[string]string) error { func testSetup(rootDir string, args []string, env map[string]string) error {
clearConfig(defaultRoot)
clearConfig(rootDir)
rootCmd := testRootCmd() rootCmd := testRootCmd()
cmd := cli.PrepareBaseCmd(rootCmd, "TM", defaultRoot)
cmd := cli.PrepareBaseCmd(rootCmd, "TM", rootDir)
// run with the args and env // run with the args and env
args = append([]string{rootCmd.Use}, args...) args = append([]string{rootCmd.Use}, args...)
@ -63,6 +59,7 @@ func testSetup(rootDir string, args []string, env map[string]string) error {
} }
func TestRootHome(t *testing.T) { func TestRootHome(t *testing.T) {
defaultRoot := t.TempDir()
newRoot := filepath.Join(defaultRoot, "something-else") newRoot := filepath.Join(defaultRoot, "something-else")
cases := []struct { cases := []struct {
args []string args []string
@ -105,6 +102,7 @@ func TestRootFlagsEnv(t *testing.T) {
{nil, map[string]string{"TM_LOG_LEVEL": "debug"}, "debug"}, // right env {nil, map[string]string{"TM_LOG_LEVEL": "debug"}, "debug"}, // right env
} }
defaultRoot := t.TempDir()
for i, tc := range cases { for i, tc := range cases {
idxString := strconv.Itoa(i) idxString := strconv.Itoa(i)
@ -135,6 +133,7 @@ func TestRootConfig(t *testing.T) {
} }
for i, tc := range cases { for i, tc := range cases {
defaultRoot := t.TempDir()
idxString := strconv.Itoa(i) idxString := strconv.Itoa(i)
clearConfig(defaultRoot) clearConfig(defaultRoot)


Loading…
Cancel
Save