lotus/node/config/load_test.go
Łukasz Magiera 08b22edd89 fix make gen
2022-08-29 16:25:30 +02:00

67 lines
1.6 KiB
Go

// stm: #unit
package config
import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDecodeNothing(t *testing.T) {
//stm: @NODE_CONFIG_LOAD_FILE_002
assert := assert.New(t)
{
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")
}
{
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) {
//stm: @NODE_CONFIG_LOAD_FILE_003
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")
}
}