mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
Add basic tests on config, mainly to raise test coverage
This commit is contained in:
28
config/config_test.go
Normal file
28
config/config_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultConfig(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
// set up some defaults
|
||||||
|
cfg := DefaultConfig()
|
||||||
|
assert.NotNil(cfg.P2P)
|
||||||
|
assert.NotNil(cfg.Mempool)
|
||||||
|
assert.NotNil(cfg.Consensus)
|
||||||
|
|
||||||
|
// check the root dir stuff...
|
||||||
|
cfg.SetRoot("/foo")
|
||||||
|
cfg.Genesis = "bar"
|
||||||
|
cfg.DBPath = "/opt/data"
|
||||||
|
cfg.Mempool.WalPath = "wal/mem/"
|
||||||
|
|
||||||
|
assert.Equal("/foo/bar", cfg.GenesisFile())
|
||||||
|
assert.Equal("/opt/data", cfg.DBDir())
|
||||||
|
assert.Equal("/foo/wal/mem", cfg.Mempool.WalDir())
|
||||||
|
|
||||||
|
}
|
||||||
57
config/toml_test.go
Normal file
57
config/toml_test.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"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) {
|
||||||
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
|
// setup temp dir for test
|
||||||
|
tmpDir, err := ioutil.TempDir("", "config-test")
|
||||||
|
require.Nil(err)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
// create root dir
|
||||||
|
EnsureRoot(tmpDir)
|
||||||
|
|
||||||
|
// make sure config is set properly
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml"))
|
||||||
|
require.Nil(err)
|
||||||
|
assert.Equal([]byte(defaultConfig("anonymous")), data)
|
||||||
|
|
||||||
|
ensureFiles(t, tmpDir, "data")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnsureTestRoot(t *testing.T) {
|
||||||
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
|
testName := "ensureTestRoot"
|
||||||
|
|
||||||
|
// create root dir
|
||||||
|
cfg := ResetTestRoot(testName)
|
||||||
|
rootDir := cfg.RootDir
|
||||||
|
|
||||||
|
// make sure config is set properly
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(rootDir, "config.toml"))
|
||||||
|
require.Nil(err)
|
||||||
|
assert.Equal([]byte(testConfig("anonymous")), data)
|
||||||
|
|
||||||
|
// TODO: make sure the cfg returned and testconfig are the same!
|
||||||
|
|
||||||
|
ensureFiles(t, rootDir, "data", "genesis.json", "priv_validator.json")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user