config: Test deafult toml roundtrip
This commit is contained in:
parent
6f890a3edd
commit
78eaac6534
54
node/config/def_test.go
Normal file
54
node/config/def_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDefaultFullNodeRoundtrip(t *testing.T) {
|
||||
c := DefaultFullNode()
|
||||
|
||||
var s string
|
||||
{
|
||||
buf := new(bytes.Buffer)
|
||||
_, _ = buf.WriteString("# Default config:\n")
|
||||
e := toml.NewEncoder(buf)
|
||||
require.NoError(t, e.Encode(c))
|
||||
|
||||
s = buf.String()
|
||||
}
|
||||
|
||||
c2, err := FromReader(strings.NewReader(s), DefaultFullNode())
|
||||
require.NoError(t, err)
|
||||
|
||||
fmt.Println(s)
|
||||
|
||||
require.True(t, reflect.DeepEqual(c, c2))
|
||||
}
|
||||
|
||||
func TestDefaultMinerRoundtrip(t *testing.T) {
|
||||
c := DefaultStorageMiner()
|
||||
|
||||
var s string
|
||||
{
|
||||
buf := new(bytes.Buffer)
|
||||
_, _ = buf.WriteString("# Default config:\n")
|
||||
e := toml.NewEncoder(buf)
|
||||
require.NoError(t, e.Encode(c))
|
||||
|
||||
s = buf.String()
|
||||
}
|
||||
|
||||
c2, err := FromReader(strings.NewReader(s), DefaultStorageMiner())
|
||||
require.NoError(t, err)
|
||||
|
||||
fmt.Println(s)
|
||||
|
||||
require.True(t, reflect.DeepEqual(c, c2))
|
||||
}
|
@ -53,5 +53,4 @@ func ConfigComment(t interface{}) ([]byte, error) {
|
||||
b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n#"))
|
||||
b = bytes.ReplaceAll(b, []byte("#["), []byte("["))
|
||||
return b, nil
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user