evcc-io/util/decoder_test.go
2023-12-06 18:29:32 +01:00

37 lines
737 B
Go

package util
import (
"testing"
"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDecodeNil(t *testing.T) {
var dst struct {
User, Password string
}
decoderConfig := &mapstructure.DecoderConfig{
Result: &dst,
ErrorUnused: true,
WeaklyTypedInput: true,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.TextUnmarshallerHookFunc(),
),
}
decoder, err := mapstructure.NewDecoder(decoderConfig)
require.NoError(t, err)
err = decoder.Decode(map[string]any{
"user": nil,
})
require.NoError(t, err)
assert.Equal(t, struct {
User, Password string
}{}, dst)
}