mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 06:31:57 +00:00
tests: remove panics from test fixtures (#7522)
This commit is contained in:
@@ -3,7 +3,6 @@ package bits
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
@@ -149,9 +148,8 @@ func TestBytes(t *testing.T) {
|
||||
bA := NewBitArray(4)
|
||||
bA.SetIndex(0, true)
|
||||
check := func(bA *BitArray, bz []byte) {
|
||||
if !bytes.Equal(bA.Bytes(), bz) {
|
||||
panic(fmt.Sprintf("Expected %X but got %X", bz, bA.Bytes()))
|
||||
}
|
||||
require.True(t, bytes.Equal(bA.Bytes(), bz),
|
||||
"Expected %X but got %X", bz, bA.Bytes())
|
||||
}
|
||||
check(bA, []byte{0x01})
|
||||
bA.SetIndex(3, true)
|
||||
|
||||
@@ -54,11 +54,10 @@ func TestSetupEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func tempDir() string {
|
||||
func tempDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
cdir, err := os.MkdirTemp("", "test-cli")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
return cdir
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ func TestSetupConfig(t *testing.T) {
|
||||
// we pre-create two config files we can refer to in the rest of
|
||||
// the test cases.
|
||||
cval1 := "fubble"
|
||||
conf1 := tempDir()
|
||||
conf1 := tempDir(t)
|
||||
err := WriteConfigVals(conf1, map[string]string{"boo": cval1})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -125,11 +124,11 @@ func TestSetupUnmarshal(t *testing.T) {
|
||||
// we pre-create two config files we can refer to in the rest of
|
||||
// the test cases.
|
||||
cval1, cval2 := "someone", "else"
|
||||
conf1 := tempDir()
|
||||
conf1 := tempDir(t)
|
||||
err := WriteConfigVals(conf1, map[string]string{"name": cval1})
|
||||
require.NoError(t, err)
|
||||
// even with some ignored fields, should be no problem
|
||||
conf2 := tempDir()
|
||||
conf2 := tempDir(t)
|
||||
err = WriteConfigVals(conf2, map[string]string{"name": cval2, "foo": "bar"})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user