From 46aa352f9b4f653b288086d173f61b8e52e9cebd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 6 Oct 2017 22:35:45 +0200 Subject: [PATCH] accounts/keystore: style nits --- accounts/keystore/account_cache.go | 3 +-- accounts/keystore/account_cache_test.go | 28 ++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index fb7c6ec7ca..8db933cc25 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -20,6 +20,7 @@ import ( "bufio" "encoding/json" "fmt" + "io/ioutil" "os" "path/filepath" "sort" @@ -27,8 +28,6 @@ import ( "sync" "time" - "io/ioutil" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" diff --git a/accounts/keystore/account_cache_test.go b/accounts/keystore/account_cache_test.go index 134ae6230f..746d1f15e0 100644 --- a/accounts/keystore/account_cache_test.go +++ b/accounts/keystore/account_cache_test.go @@ -18,6 +18,7 @@ package keystore import ( "fmt" + "io/ioutil" "math/rand" "os" "path/filepath" @@ -30,7 +31,6 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" - "io/ioutil" ) var ( @@ -318,6 +318,8 @@ func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error { // TestUpdatedKeyfileContents tests that updating the contents of a keystore file // is noticed by the watcher, and the account cache is updated accordingly func TestUpdatedKeyfileContents(t *testing.T) { + t.Parallel() + // Create a temporary kesytore to test with rand.Seed(time.Now().UnixNano()) dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-watch-test-%d-%d", os.Getpid(), rand.Int())) @@ -347,19 +349,8 @@ func TestUpdatedKeyfileContents(t *testing.T) { return } - copyContents := func(dst, src string) error { - data, err := ioutil.ReadFile(src) - if err != nil { - return err - } - err = ioutil.WriteFile(dst, data, 0644) - if err != nil { - return err - } - return nil - } // Now replace file contents - if err := copyContents(file, cachetestAccounts[1].URL.Path); err != nil { + if err := forceCopyFile(file, cachetestAccounts[1].URL.Path); err != nil { t.Fatal(err) return } @@ -372,7 +363,7 @@ func TestUpdatedKeyfileContents(t *testing.T) { } // Now replace file contents again - if err := copyContents(file, cachetestAccounts[2].URL.Path); err != nil { + if err := forceCopyFile(file, cachetestAccounts[2].URL.Path); err != nil { t.Fatal(err) return } @@ -394,3 +385,12 @@ func TestUpdatedKeyfileContents(t *testing.T) { return } } + +// forceCopyFile is like cp.CopyFile, but doesn't complain if the destination exists. +func forceCopyFile(dst, src string) error { + data, err := ioutil.ReadFile(src) + if err != nil { + return err + } + return ioutil.WriteFile(dst, data, 0644) +}