chore: test private struct type squashed decoding
This commit is contained in:
parent
403f3f0f43
commit
0e2c96286b
1 changed files with 69 additions and 0 deletions
69
meter/usage_battery_test.go
Normal file
69
meter/usage_battery_test.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue