Browse Source

types: fix path handling in node key tests (#7493) (#7502)

These tests use a deterministic and unseeded random source to generate
non-colliding filenames for testing. When testing locally, this means tests are
not hermetic from one run to the next.

Use proper temp directories, and clean up after they're done.

(cherry picked from commit 5f85c8f536)

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
pull/7514/head
mergify[bot] 2 years ago
committed by GitHub
parent
commit
7770ab0efd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions
  1. +3
    -4
      types/node_key_test.go

+ 3
- 4
types/node_key_test.go View File

@ -7,12 +7,11 @@ import (
"github.com/stretchr/testify/require"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
)
func TestLoadOrGenNodeKey(t *testing.T) {
filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json")
filePath := filepath.Join(t.TempDir(), "peer_id.json")
nodeKey, err := types.LoadOrGenNodeKey(filePath)
require.Nil(t, err)
@ -23,7 +22,7 @@ func TestLoadOrGenNodeKey(t *testing.T) {
}
func TestLoadNodeKey(t *testing.T) {
filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json")
filePath := filepath.Join(t.TempDir(), "peer_id.json")
_, err := types.LoadNodeKey(filePath)
require.True(t, os.IsNotExist(err))
@ -37,7 +36,7 @@ func TestLoadNodeKey(t *testing.T) {
}
func TestNodeKeySaveAs(t *testing.T) {
filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json")
filePath := filepath.Join(t.TempDir(), "peer_id.json")
require.NoFileExists(t, filePath)
nodeKey := types.GenNodeKey()


Loading…
Cancel
Save