Browse Source

config: lil fixes

pull/792/head
Zach Ramsay 7 years ago
parent
commit
a92a32b862
2 changed files with 12 additions and 6 deletions
  1. +2
    -2
      config/toml.go
  2. +10
    -4
      config/toml_test.go

+ 2
- 2
config/toml.go View File

@ -35,7 +35,7 @@ func EnsureRoot(rootDir string) {
// Write default config file if missing. // Write default config file if missing.
if !cmn.FileExists(configFilePath) { if !cmn.FileExists(configFilePath) {
cmn.MustWriteFile(configFilePath, []byte(defaultConfig(defaultMoniker)), 0644)
writeConfigFile(configFilePath)
} }
} }
@ -241,7 +241,7 @@ func ResetTestRoot(testName string) *Config {
// Write default config file if missing. // Write default config file if missing.
if !cmn.FileExists(configFilePath) { if !cmn.FileExists(configFilePath) {
cmn.MustWriteFile(configFilePath, []byte(testConfig(defaultMoniker)), 0644)
writeConfigFile(configFilePath)
} }
if !cmn.FileExists(genesisFilePath) { if !cmn.FileExists(genesisFilePath) {
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)


+ 10
- 4
config/toml_test.go View File

@ -20,7 +20,7 @@ func ensureFiles(t *testing.T, rootDir string, files ...string) {
} }
func TestEnsureRoot(t *testing.T) { func TestEnsureRoot(t *testing.T) {
assert, require := assert.New(t), require.New(t)
require := require.New(t)
// setup temp dir for test // setup temp dir for test
tmpDir, err := ioutil.TempDir("", "config-test") tmpDir, err := ioutil.TempDir("", "config-test")
@ -33,13 +33,16 @@ func TestEnsureRoot(t *testing.T) {
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath)) data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
require.Nil(err) require.Nil(err)
assert.Equal([]byte(defaultConfig(defaultMoniker)), data)
if !checkConfig(string(data)) {
t.Fatalf("config file missing some information")
}
ensureFiles(t, tmpDir, "data") ensureFiles(t, tmpDir, "data")
} }
func TestEnsureTestRoot(t *testing.T) { func TestEnsureTestRoot(t *testing.T) {
assert, require := assert.New(t), require.New(t)
require := require.New(t)
testName := "ensureTestRoot" testName := "ensureTestRoot"
@ -50,7 +53,10 @@ func TestEnsureTestRoot(t *testing.T) {
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath)) data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
require.Nil(err) require.Nil(err)
assert.Equal([]byte(testConfig(defaultMoniker)), data)
if !checkConfig(string(data)) {
t.Fatalf("config file missing some information")
}
// TODO: make sure the cfg returned and testconfig are the same! // TODO: make sure the cfg returned and testconfig are the same!
baseConfig := DefaultBaseConfig() baseConfig := DefaultBaseConfig()


Loading…
Cancel
Save