config: Test deafult toml roundtrip

This commit is contained in:
Łukasz Magiera 2020-08-12 19:55:43 +02:00
parent 6f890a3edd
commit 78eaac6534
2 changed files with 54 additions and 1 deletions

54
node/config/def_test.go Normal file
View 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))
}

View File

@ -53,5 +53,4 @@ func ConfigComment(t interface{}) ([]byte, error) {
b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n#")) b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n#"))
b = bytes.ReplaceAll(b, []byte("#["), []byte("[")) b = bytes.ReplaceAll(b, []byte("#["), []byte("["))
return b, nil return b, nil
} }