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