mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 14:22:16 +00:00
* improve ResetTestRootWithChainID() concurrency safety Rely on ioutil.TempDir() to create test root directories and ensure multiple same-chain id test cases can run in parallel. * Update config/toml.go Co-Authored-By: alessio <quadrispro@ubuntu.com> * clean up test directories after completion Closes: #1034 * Remove redundant EnsureDir call * s/PanicSafety()/panic()/s * Put create dir functionality back in ResetTestRootWithChainID * Place test directories in OS's tempdir In modern UNIX and UNIX-like systems /tmp is very often mounted as tmpfs. This might speed test execution a bit. * Set 0700 to a const * rootsDirs -> configRootDirs * Don't double remove directories * Avoid global variables * Fix consensus tests * Reduce defer stack * Address review comments * Try to fix tests * Update CHANGELOG_PENDING.md Co-Authored-By: alessio <quadrispro@ubuntu.com> * Update consensus/common_test.go Co-Authored-By: alessio <quadrispro@ubuntu.com> * Update consensus/common_test.go Co-Authored-By: alessio <quadrispro@ubuntu.com>
96 lines
1.9 KiB
Go
96 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func ensureFiles(t *testing.T, rootDir string, files ...string) {
|
|
for _, f := range files {
|
|
p := rootify(rootDir, f)
|
|
_, err := os.Stat(p)
|
|
assert.Nil(t, err, p)
|
|
}
|
|
}
|
|
|
|
func TestEnsureRoot(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
// setup temp dir for test
|
|
tmpDir, err := ioutil.TempDir("", "config-test")
|
|
require.Nil(err)
|
|
defer os.RemoveAll(tmpDir) // nolint: errcheck
|
|
|
|
// create root dir
|
|
EnsureRoot(tmpDir)
|
|
|
|
// make sure config is set properly
|
|
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
|
|
require.Nil(err)
|
|
|
|
if !checkConfig(string(data)) {
|
|
t.Fatalf("config file missing some information")
|
|
}
|
|
|
|
ensureFiles(t, tmpDir, "data")
|
|
}
|
|
|
|
func TestEnsureTestRoot(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
testName := "ensureTestRoot"
|
|
|
|
// create root dir
|
|
cfg := ResetTestRoot(testName)
|
|
defer os.RemoveAll(cfg.RootDir)
|
|
rootDir := cfg.RootDir
|
|
|
|
// make sure config is set properly
|
|
data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
|
|
require.Nil(err)
|
|
|
|
if !checkConfig(string(data)) {
|
|
t.Fatalf("config file missing some information")
|
|
}
|
|
|
|
// TODO: make sure the cfg returned and testconfig are the same!
|
|
baseConfig := DefaultBaseConfig()
|
|
ensureFiles(t, rootDir, defaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState)
|
|
}
|
|
|
|
func checkConfig(configFile string) bool {
|
|
var valid bool
|
|
|
|
// list of words we expect in the config
|
|
var elems = []string{
|
|
"moniker",
|
|
"seeds",
|
|
"proxy_app",
|
|
"fast_sync",
|
|
"create_empty_blocks",
|
|
"peer",
|
|
"timeout",
|
|
"broadcast",
|
|
"send",
|
|
"addr",
|
|
"wal",
|
|
"propose",
|
|
"max",
|
|
"genesis",
|
|
}
|
|
for _, e := range elems {
|
|
if !strings.Contains(configFile, e) {
|
|
valid = false
|
|
} else {
|
|
valid = true
|
|
}
|
|
}
|
|
return valid
|
|
}
|