evcc-io/core/loadpoint_sync_test.go
Martin Weinelt daee304a49
chore: migrate from unmaintained mockgen (#11547)
The golang mock package has been archived and is now maintained by uber.

> Update, June 2023: This repo and tool are no longer maintained. Please
> see go.uber.org/mock for a maintained fork instead.

[1] https://github.com/golang/mock
[2] https://github.com/uber-go/mock
2024-01-08 11:13:27 +01:00

49 lines
1.1 KiB
Go

package core
import (
"testing"
"github.com/benbjohnson/clock"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func TestSyncCharger(t *testing.T) {
tc := []struct {
status api.ChargeStatus
expected, actual, corrected bool
}{
{api.StatusA, false, false, false},
{api.StatusC, false, false, true}, // disabled but charging
{api.StatusA, false, true, true},
{api.StatusA, true, false, false},
{api.StatusA, true, true, true},
}
ctrl := gomock.NewController(t)
for _, tc := range tc {
t.Logf("%+v", tc)
charger := api.NewMockCharger(ctrl)
charger.EXPECT().Enabled().Return(tc.actual, nil).AnyTimes()
if tc.status == api.StatusC {
charger.EXPECT().Enable(tc.corrected).Times(1)
}
lp := &Loadpoint{
log: util.NewLogger("foo"),
clock: clock.New(),
charger: charger,
status: tc.status,
enabled: tc.expected,
}
require.NoError(t, lp.syncCharger())
assert.Equal(t, tc.corrected, lp.enabled)
}
}