1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-25 21:41:20 +00:00
go_helpers/fieldcollection/marshalJSON_test.go
Knut Ahlers 6efbc2dd11
Add validation to fieldcollection
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-04-03 19:03:45 +02:00

23 lines
503 B
Go

package fieldcollection
import (
"bytes"
"encoding/json"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFieldCollectionJSONMarshal(t *testing.T) {
var (
buf = new(bytes.Buffer)
raw = `{"key1":"test1","key2":"test2"}`
f = NewFieldCollection()
)
require.NoError(t, json.NewDecoder(strings.NewReader(raw)).Decode(f))
require.NoError(t, json.NewEncoder(buf).Encode(f))
assert.Equal(t, raw, strings.TrimSpace(buf.String()))
}