config: fix broken test (#9309)

This commit is contained in:
Callum Waters
2022-09-07 11:42:20 +02:00
committed by GitHub
parent 1944dfd873
commit 2ae117ef62

View File

@@ -3,7 +3,6 @@ package config
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -33,9 +32,7 @@ func TestEnsureRoot(t *testing.T) {
data, err := os.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath)) data, err := os.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
require.Nil(err) require.Nil(err)
if !checkConfig(string(data)) { assertValidConfig(t, string(data))
t.Fatalf("config file missing some information")
}
ensureFiles(t, tmpDir, "data") ensureFiles(t, tmpDir, "data")
} }
@@ -54,24 +51,21 @@ func TestEnsureTestRoot(t *testing.T) {
data, err := os.ReadFile(filepath.Join(rootDir, defaultConfigFilePath)) data, err := os.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
require.Nil(err) require.Nil(err)
if !checkConfig(string(data)) { assertValidConfig(t, 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()
ensureFiles(t, rootDir, defaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState) ensureFiles(t, rootDir, defaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState)
} }
func checkConfig(configFile string) bool { func assertValidConfig(t *testing.T, configFile string) {
var valid bool t.Helper()
// list of words we expect in the config // list of words we expect in the config
var elems = []string{ var elems = []string{
"moniker", "moniker",
"seeds", "seeds",
"proxy_app", "proxy_app",
"fast_sync", "block_sync",
"create_empty_blocks", "create_empty_blocks",
"peer", "peer",
"timeout", "timeout",
@@ -84,11 +78,6 @@ func checkConfig(configFile string) bool {
"genesis", "genesis",
} }
for _, e := range elems { for _, e := range elems {
if !strings.Contains(configFile, e) { assert.Contains(t, configFile, e)
valid = false
} else {
valid = true
}
} }
return valid
} }