Skip to content

Commit

Permalink
test: fix cmd test temp directory (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo authored Mar 8, 2023
1 parent 161bcd2 commit 7404e1b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/client/cli/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli_test
import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,14 +16,24 @@ import (
)

func TestInitCmd(t *testing.T) {
nodeHome := os.TempDir()
tmp := os.TempDir()
nodeHome := filepath.Join(tmp, "test_init_cmd")

// clean up previous test home directory
err := os.RemoveAll(nodeHome)
require.NoError(t, err)

// create new test home directory
err = os.Mkdir(nodeHome, 0755)
require.NoError(t, err)

rootCmd, _ := cli.NewRootCmd()
rootCmd.SetArgs([]string{
"init", // Test the init cmd
"regenapp-test", // Moniker
fmt.Sprintf("--%s=%s", flags.FlagHome, nodeHome), // Set home flag
"init",
"test",
fmt.Sprintf("--%s=%s", flags.FlagHome, nodeHome),
})

err := cmd.Execute(rootCmd, app.EnvPrefix, app.DefaultNodeHome)
err = cmd.Execute(rootCmd, app.EnvPrefix, nodeHome)
require.NoError(t, err)
}

0 comments on commit 7404e1b

Please sign in to comment.