69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package meter
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/evcc-io/evcc/util"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBatterySocLimits(t *testing.T) {
|
|
other := map[string]any{
|
|
"minsoc": 1,
|
|
"maxsoc": 99,
|
|
}
|
|
|
|
expected := batterySocLimits{
|
|
MinSoc: 1,
|
|
MaxSoc: 99,
|
|
}
|
|
|
|
{
|
|
var res batterySocLimits
|
|
require.NoError(t, util.DecodeOther(other, &res))
|
|
require.Equal(t, expected, res)
|
|
}
|
|
|
|
{
|
|
var res struct {
|
|
batterySocLimits `mapstructure:",squash"`
|
|
}
|
|
require.NoError(t, util.DecodeOther(other, &res))
|
|
require.Equal(t, expected, res.batterySocLimits)
|
|
}
|
|
|
|
{
|
|
var res struct {
|
|
BatterySocLimits batterySocLimits `mapstructure:",squash"`
|
|
}
|
|
require.NoError(t, util.DecodeOther(other, &res))
|
|
require.Equal(t, expected, res.BatterySocLimits)
|
|
}
|
|
|
|
{
|
|
res := struct {
|
|
batterySocLimits `mapstructure:",squash"`
|
|
}{
|
|
batterySocLimits: batterySocLimits{
|
|
MinSoc: 20,
|
|
MaxSoc: 95,
|
|
},
|
|
}
|
|
require.NoError(t, util.DecodeOther(other, &res))
|
|
require.Equal(t, expected, res.batterySocLimits)
|
|
}
|
|
|
|
{
|
|
res := struct {
|
|
pvMaxACPower `mapstructure:",squash"`
|
|
batterySocLimits `mapstructure:",squash"`
|
|
}{
|
|
batterySocLimits: batterySocLimits{
|
|
MinSoc: 20,
|
|
MaxSoc: 95,
|
|
},
|
|
}
|
|
require.NoError(t, util.DecodeOther(other, &res))
|
|
require.Equal(t, expected, res.batterySocLimits)
|
|
}
|
|
}
|