lotus/node/config/load_test.go

67 lines
1.5 KiB
Go
Raw Normal View History

2021-11-01 00:24:26 +00:00
//stm: #unit
package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDecodeNothing(t *testing.T) {
assert := assert.New(t)
{
2021-11-01 00:24:26 +00:00
//stm: @NODE_CONFIG_001
cfg, err := FromFile(os.DevNull, DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(DefaultFullNode(), cfg,
"config from empty file should be the same as default")
}
{
2021-11-01 00:24:26 +00:00
//stm: @NODE_CONFIG_002
cfg, err := FromFile("./does-not-exist.toml", DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(DefaultFullNode(), cfg,
"config from not exisiting file should be the same as default")
}
}
func TestParitalConfig(t *testing.T) {
assert := assert.New(t)
cfgString := `
[API]
Timeout = "10s"
`
expected := DefaultFullNode()
expected.API.Timeout = Duration(10 * time.Second)
{
cfg, err := FromReader(bytes.NewReader([]byte(cfgString)), DefaultFullNode())
assert.NoError(err, "error should be nil")
assert.Equal(expected, cfg,
"config from reader should contain changes")
}
{
f, err := ioutil.TempFile("", "config-*.toml")
fname := f.Name()
assert.NoError(err, "tmp file shold not error")
_, err = f.WriteString(cfgString)
assert.NoError(err, "writing to tmp file should not error")
err = f.Close()
assert.NoError(err, "closing tmp file should not error")
defer os.Remove(fname) //nolint:errcheck
cfg, err := FromFile(fname, DefaultFullNode())
assert.Nil(err, "error should be nil")
assert.Equal(expected, cfg,
"config from reader should contain changes")
}
}