You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. package config
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func ensureFiles(t *testing.T, rootDir string, files ...string) {
  11. for _, f := range files {
  12. p := rootify(rootDir, f)
  13. _, err := os.Stat(p)
  14. assert.Nil(t, err, p)
  15. }
  16. }
  17. func TestEnsureRoot(t *testing.T) {
  18. assert, require := assert.New(t), require.New(t)
  19. // setup temp dir for test
  20. tmpDir, err := ioutil.TempDir("", "config-test")
  21. require.Nil(err)
  22. defer os.RemoveAll(tmpDir) // nolint: errcheck
  23. // create root dir
  24. EnsureRoot(tmpDir)
  25. // make sure config is set properly
  26. data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml"))
  27. require.Nil(err)
  28. assert.Equal([]byte(defaultConfig(defaultMoniker)), data)
  29. ensureFiles(t, tmpDir, "data")
  30. }
  31. func TestEnsureTestRoot(t *testing.T) {
  32. assert, require := assert.New(t), require.New(t)
  33. testName := "ensureTestRoot"
  34. // create root dir
  35. cfg := ResetTestRoot(testName)
  36. rootDir := cfg.RootDir
  37. // make sure config is set properly
  38. data, err := ioutil.ReadFile(filepath.Join(rootDir, "config.toml"))
  39. require.Nil(err)
  40. assert.Equal([]byte(testConfig(defaultMoniker)), data)
  41. // TODO: make sure the cfg returned and testconfig are the same!
  42. ensureFiles(t, rootDir, "data", "genesis.json", "priv_validator.json")
  43. }