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.

54 lines
1.3 KiB

  1. package config
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestDefaultConfig(t *testing.T) {
  8. assert := assert.New(t)
  9. // set up some defaults
  10. cfg := DefaultConfig()
  11. assert.NotNil(cfg.P2P)
  12. assert.NotNil(cfg.Mempool)
  13. assert.NotNil(cfg.Consensus)
  14. // check the root dir stuff...
  15. cfg.SetRoot("/foo")
  16. cfg.Genesis = "bar"
  17. cfg.DBPath = "/opt/data"
  18. cfg.Mempool.WalPath = "wal/mem/"
  19. assert.Equal("/foo/bar", cfg.GenesisFile())
  20. assert.Equal("/opt/data", cfg.DBDir())
  21. assert.Equal("/foo/wal/mem", cfg.Mempool.WalDir())
  22. }
  23. func TestConfigValidateBasic(t *testing.T) {
  24. cfg := DefaultConfig()
  25. assert.NoError(t, cfg.ValidateBasic())
  26. // tamper with timeout_propose
  27. cfg.Consensus.TimeoutPropose = -10 * time.Second
  28. assert.Error(t, cfg.ValidateBasic())
  29. }
  30. func TestTLSConfiguration(t *testing.T) {
  31. assert := assert.New(t)
  32. cfg := DefaultConfig()
  33. cfg.SetRoot("/home/user")
  34. cfg.RPC.TLSCertFile = "file.crt"
  35. assert.Equal("/home/user/config/file.crt", cfg.RPC.CertFile())
  36. cfg.RPC.TLSKeyFile = "file.key"
  37. assert.Equal("/home/user/config/file.key", cfg.RPC.KeyFile())
  38. cfg.RPC.TLSCertFile = "/abs/path/to/file.crt"
  39. assert.Equal("/abs/path/to/file.crt", cfg.RPC.CertFile())
  40. cfg.RPC.TLSKeyFile = "/abs/path/to/file.key"
  41. assert.Equal("/abs/path/to/file.key", cfg.RPC.KeyFile())
  42. }