Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace testutil.NewTestCaseDir() with Go1.15's T.TempDir() #7014

Merged
merged 20 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ It is being used to build [`Gaia`](https://github.com/cosmos/gaia), the first im
**WARNING**: The SDK has mostly stabilized, but we are still making some
breaking changes.

**Note**: Requires [Go 1.14+](https://golang.org/dl/)
**Note**: Requires [Go 1.15+](https://golang.org/dl/)

## Quick Start

Expand Down
10 changes: 2 additions & 8 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

// Prepare a keybase
kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
require.NotNil(t, kbHome)
t.Cleanup(kbCleanUp)
kbHome := t.TempDir()

cmd.SetArgs([]string{
"keyname1",
Expand Down Expand Up @@ -86,11 +84,7 @@ func Test_runAddCmdLedger(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)

// Prepare a keybase
kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
require.NotNil(t, kbHome)
t.Cleanup(kbCleanUp)
kbHome := t.TempDir()

cmd.SetArgs([]string{
"keyname1",
Expand Down
7 changes: 2 additions & 5 deletions client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ func Test_runAddCmdBasic(t *testing.T) {
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

mockIn := testutil.ApplyMockIODiscardOutErr(cmd)

kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
require.NotNil(t, kbHome)
t.Cleanup(kbCleanUp)

kbHome := t.TempDir()
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)

require.NoError(t, err)
t.Cleanup(func() {
_ = kb.Delete("keyname1")
Expand Down
4 changes: 1 addition & 3 deletions client/keys/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (

func Test_runDeleteCmd(t *testing.T) {
// Now add a temporary keybase
kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)

kbHome := t.TempDir()
cmd := DeleteKeyCommand()
cmd.Flags().AddFlagSet(Commands(kbHome).PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
Expand Down
3 changes: 1 addition & 2 deletions client/keys/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func Test_runExportCmd(t *testing.T) {
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)

// Now add a temporary keybase
kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)
kbHome := t.TempDir()

// create a key
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)
Expand Down
5 changes: 2 additions & 3 deletions client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ func Test_runImportCmd(t *testing.T) {
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)

// Now add a temporary keybase
kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)

kbHome := t.TempDir()
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)

require.NoError(t, err)
t.Cleanup(func() {
kb.Delete("keyname1") // nolint:errcheck
Expand Down
7 changes: 2 additions & 5 deletions client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func Test_runListCmd(t *testing.T) {
cmd := ListKeysCmd()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

kbHome1, cleanUp1 := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp1)

kbHome2, cleanUp2 := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp2)
kbHome1 := t.TempDir()
kbHome2 := t.TempDir()

mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn)
Expand Down
6 changes: 2 additions & 4 deletions client/keys/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ func Test_runMigrateCmd(t *testing.T) {
_ = testutil.ApplyMockIODiscardOutErr(cmd)
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
copy.Copy("testdata", kbHome)
assert.NotNil(t, kbHome)
t.Cleanup(kbCleanUp)
kbHome := t.TempDir()

copy.Copy("testdata", kbHome)
cmd.SetArgs([]string{
"keyname1",
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
Expand Down
4 changes: 1 addition & 3 deletions client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func Test_runShowCmd(t *testing.T) {
cmd.SetArgs([]string{"invalid1", "invalid2"})
require.EqualError(t, cmd.Execute(), "invalid1 is not a valid name or address: decoding bech32 failed: invalid index of 1")

kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)

kbHome := t.TempDir()
fakeKeyName1 := "runShowCmd_Key1"
fakeKeyName2 := "runShowCmd_Key2"

Expand Down
6 changes: 2 additions & 4 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"testing"

"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/x/auth/signing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -115,10 +114,9 @@ func TestBuildUnsignedTx(t *testing.T) {
}

func TestSign(t *testing.T) {
dir, clean := testutil.NewTestCaseDir(t)
t.Cleanup(clean)

dir := t.TempDir()
path := hd.CreateHDPath(118, 0, 0).String()

kr, err := keyring.New(t.Name(), "test", dir, nil)
require.NoError(t, err)

Expand Down
8 changes: 3 additions & 5 deletions crypto/keyring/keyring_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -52,8 +51,8 @@ func TestInMemoryCreateLedger(t *testing.T) {
// TestSignVerify does some detailed checks on how we sign and validate
// signatures
func TestSignVerifyKeyRingWithLedger(t *testing.T) {
dir, cleanup := testutil.NewTestCaseDir(t)
t.Cleanup(cleanup)
dir := t.TempDir()

kb, err := New("keybasename", "test", dir, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -89,8 +88,7 @@ func TestSignVerifyKeyRingWithLedger(t *testing.T) {
}

func TestAltKeyring_SaveLedgerKey(t *testing.T) {
dir, clean := testutil.NewTestCaseDir(t)
t.Cleanup(clean)
dir := t.TempDir()

keyring, err := New(t.Name(), BackendTest, dir, nil)
require.NoError(t, err)
Expand Down