github.com/devwanda/aphelion-staking@v0.33.9/config/toml_test.go (about) 1 package config 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "strings" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func ensureFiles(t *testing.T, rootDir string, files ...string) { 15 for _, f := range files { 16 p := rootify(rootDir, f) 17 _, err := os.Stat(p) 18 assert.Nil(t, err, p) 19 } 20 } 21 22 func TestEnsureRoot(t *testing.T) { 23 require := require.New(t) 24 25 // setup temp dir for test 26 tmpDir, err := ioutil.TempDir("", "config-test") 27 require.Nil(err) 28 defer os.RemoveAll(tmpDir) // nolint: errcheck 29 30 // create root dir 31 EnsureRoot(tmpDir) 32 33 // make sure config is set properly 34 data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath)) 35 require.Nil(err) 36 37 if !checkConfig(string(data)) { 38 t.Fatalf("config file missing some information") 39 } 40 41 ensureFiles(t, tmpDir, "data") 42 } 43 44 func TestEnsureTestRoot(t *testing.T) { 45 require := require.New(t) 46 47 testName := "ensureTestRoot" 48 49 // create root dir 50 cfg := ResetTestRoot(testName) 51 defer os.RemoveAll(cfg.RootDir) 52 rootDir := cfg.RootDir 53 54 // make sure config is set properly 55 data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath)) 56 require.Nil(err) 57 58 if !checkConfig(string(data)) { 59 t.Fatalf("config file missing some information") 60 } 61 62 // TODO: make sure the cfg returned and testconfig are the same! 63 baseConfig := DefaultBaseConfig() 64 ensureFiles(t, rootDir, defaultDataDir, baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState) 65 } 66 67 func checkConfig(configFile string) bool { 68 var valid bool 69 70 // list of words we expect in the config 71 var elems = []string{ 72 "moniker", 73 "seeds", 74 "proxy_app", 75 "fast_sync", 76 "create_empty_blocks", 77 "peer", 78 "timeout", 79 "broadcast", 80 "send", 81 "addr", 82 "wal", 83 "propose", 84 "max", 85 "genesis", 86 } 87 for _, e := range elems { 88 if !strings.Contains(configFile, e) { 89 valid = false 90 } else { 91 valid = true 92 } 93 } 94 return valid 95 }