From 7bc78e03d0cd38d2e07a6b6b00c2bf76d2c4b467 Mon Sep 17 00:00:00 2001 From: Frednesto Date: Fri, 23 Feb 2024 16:21:12 -0500 Subject: [PATCH] fix(issue-253): fix all go vet errors --- ocpp1.6_test/cancel_reservation_test.go | 7 ++-- ocpp1.6_test/clear_charging_profile_test.go | 7 ++-- ocpp1.6_test/common_test.go | 14 +++---- .../diagnostics_status_notification_test.go | 7 ++-- .../firmware_status_notification_test.go | 7 ++-- ocpp1.6_test/get_composite_schedule_test.go | 9 ++-- ocpp1.6_test/get_diagnostics_test.go | 6 +-- ocpp1.6_test/get_local_list_version_test.go | 7 ++-- ocpp1.6_test/ocpp16_test.go | 42 ++++++++----------- ocpp1.6_test/reserve_now_test.go | 9 ++-- ocpp1.6_test/send_local_list_test.go | 9 ++-- ocpp1.6_test/set_charging_profile_test.go | 6 +-- ocpp1.6_test/trigger_message_test.go | 7 ++-- ocpp1.6_test/update_firmware_test.go | 9 ++-- 14 files changed, 74 insertions(+), 72 deletions(-) diff --git a/ocpp1.6_test/cancel_reservation_test.go b/ocpp1.6_test/cancel_reservation_test.go index 2b74682e..97e69a7a 100644 --- a/ocpp1.6_test/cancel_reservation_test.go +++ b/ocpp1.6_test/cancel_reservation_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/reservation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -11,7 +12,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestCancelReservationRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {reservation.CancelReservationRequest{ReservationId: 42}, true}, {reservation.CancelReservationRequest{}, true}, {reservation.CancelReservationRequest{ReservationId: -1}, true}, @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestCancelReservationRequestValidation() { func (suite *OcppV16TestSuite) TestCancelReservationConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {reservation.CancelReservationConfirmation{Status: reservation.CancelReservationStatusAccepted}, true}, {reservation.CancelReservationConfirmation{Status: "invalidCancelReservationStatus"}, false}, {reservation.CancelReservationConfirmation{}, false}, @@ -50,7 +51,7 @@ func (suite *OcppV16TestSuite) TestCancelReservationE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetReservationHandler(reservationListener) + suite.chargePoint.SetReservationHandler(&reservationListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/clear_charging_profile_test.go b/ocpp1.6_test/clear_charging_profile_test.go index 2784b5c4..6ba84b84 100644 --- a/ocpp1.6_test/clear_charging_profile_test.go +++ b/ocpp1.6_test/clear_charging_profile_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging" "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestClearChargingProfileRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1), ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, StackLevel: newInt(1)}, true}, {smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1), ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile}, true}, {smartcharging.ClearChargingProfileRequest{Id: newInt(1), ConnectorId: newInt(1)}, true}, @@ -28,7 +29,7 @@ func (suite *OcppV16TestSuite) TestClearChargingProfileRequestValidation() { func (suite *OcppV16TestSuite) TestClearChargingProfileConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {smartcharging.ClearChargingProfileConfirmation{Status: smartcharging.ClearChargingProfileStatusAccepted}, true}, {smartcharging.ClearChargingProfileConfirmation{Status: "invalidClearChargingProfileStatus"}, false}, {smartcharging.ClearChargingProfileConfirmation{}, false}, @@ -64,7 +65,7 @@ func (suite *OcppV16TestSuite) TestClearChargingProfileE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetSmartChargingHandler(smartChargingListener) + suite.chargePoint.SetSmartChargingHandler(&smartChargingListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/common_test.go b/ocpp1.6_test/common_test.go index e7c342e2..92513d6a 100644 --- a/ocpp1.6_test/common_test.go +++ b/ocpp1.6_test/common_test.go @@ -21,7 +21,7 @@ func newFloat(f float64) *float64 { // Test func (suite *OcppV16TestSuite) TestIdTagInfoValidation() { - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.IdTagInfo{ExpiryDate: types.NewDateTime(time.Now()), ParentIdTag: "00000", Status: types.AuthorizationStatusAccepted}, true}, {types.IdTagInfo{ExpiryDate: types.NewDateTime(time.Now()), Status: types.AuthorizationStatusAccepted}, true}, {types.IdTagInfo{Status: types.AuthorizationStatusAccepted}, true}, @@ -38,7 +38,7 @@ func (suite *OcppV16TestSuite) TestIdTagInfoValidation() { func (suite *OcppV16TestSuite) TestChargingSchedulePeriodValidation() { t := suite.T() - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.ChargingSchedulePeriod{StartPeriod: 0, Limit: 10.0, NumberPhases: newInt(3)}, true}, {types.ChargingSchedulePeriod{StartPeriod: 0, Limit: 10.0}, true}, {types.ChargingSchedulePeriod{StartPeriod: 0}, true}, @@ -55,7 +55,7 @@ func (suite *OcppV16TestSuite) TestChargingScheduleValidation() { chargingSchedulePeriods := make([]types.ChargingSchedulePeriod, 2) chargingSchedulePeriods[0] = types.NewChargingSchedulePeriod(0, 10.0) chargingSchedulePeriods[1] = types.NewChargingSchedulePeriod(100, 8.0) - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.ChargingSchedule{Duration: newInt(0), StartSchedule: types.NewDateTime(time.Now()), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods, MinChargingRate: newFloat(1.0)}, true}, {types.ChargingSchedule{Duration: newInt(0), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods, MinChargingRate: newFloat(1.0)}, true}, {types.ChargingSchedule{Duration: newInt(0), ChargingRateUnit: types.ChargingRateUnitWatts, ChargingSchedulePeriod: chargingSchedulePeriods}, true}, @@ -72,7 +72,7 @@ func (suite *OcppV16TestSuite) TestChargingScheduleValidation() { func (suite *OcppV16TestSuite) TestChargingProfileValidation() { t := suite.T() chargingSchedule := types.NewChargingSchedule(types.ChargingRateUnitWatts, types.NewChargingSchedulePeriod(0, 10.0), types.NewChargingSchedulePeriod(100, 8.0)) - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.ChargingProfile{ChargingProfileId: 1, TransactionId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute, RecurrencyKind: types.RecurrencyKindDaily, ValidFrom: types.NewDateTime(time.Now()), ValidTo: types.NewDateTime(time.Now().Add(8 * time.Hour)), ChargingSchedule: chargingSchedule}, true}, {types.ChargingProfile{ChargingProfileId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute, ChargingSchedule: chargingSchedule}, true}, {types.ChargingProfile{ChargingProfileId: 1, StackLevel: 1, ChargingProfilePurpose: types.ChargingProfilePurposeChargePointMaxProfile, ChargingProfileKind: types.ChargingProfileKindAbsolute}, false}, @@ -91,7 +91,7 @@ func (suite *OcppV16TestSuite) TestChargingProfileValidation() { func (suite *OcppV16TestSuite) TestSampledValueValidation() { t := suite.T() - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2, Location: types.LocationBody, Unit: types.UnitOfMeasureKW}, true}, {types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2, Location: types.LocationBody}, true}, {types.SampledValue{Value: "value", Context: types.ReadingContextTransactionEnd, Format: types.ValueFormatRaw, Measurand: types.MeasurandPowerActiveExport, Phase: types.PhaseL2}, true}, @@ -110,7 +110,7 @@ func (suite *OcppV16TestSuite) TestSampledValueValidation() { } func (suite *OcppV16TestSuite) TestMeterValueValidation() { - var testTable = []GenericTestEntry{ + testTable := []GenericTestEntry{ {types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{{Value: "value"}, {Value: "value2", Unit: types.UnitOfMeasureKW}}}, true}, {types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{{Value: "value"}}}, true}, {types.MeterValue{Timestamp: types.NewDateTime(time.Now()), SampledValue: []types.SampledValue{}}, false}, @@ -180,5 +180,5 @@ func (suite *OcppV16TestSuite) TestMarshalDateTime() { func (suite *OcppV16TestSuite) TestNowDateTime() { now := types.Now() suite.NotNil(now) - suite.True(time.Now().Sub(now.Time) < 1*time.Second) + suite.True(time.Since(now.Time) < 1*time.Second) } diff --git a/ocpp1.6_test/diagnostics_status_notification_test.go b/ocpp1.6_test/diagnostics_status_notification_test.go index 3aad0d58..c25d6a30 100644 --- a/ocpp1.6_test/diagnostics_status_notification_test.go +++ b/ocpp1.6_test/diagnostics_status_notification_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -11,7 +12,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {firmware.DiagnosticsStatusNotificationRequest{Status: firmware.DiagnosticsStatusUploaded}, true}, {firmware.DiagnosticsStatusNotificationRequest{}, false}, {firmware.DiagnosticsStatusNotificationRequest{Status: "invalidDiagnosticsStatus"}, false}, @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationRequestValidatio func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {firmware.DiagnosticsStatusNotificationConfirmation{}, true}, } ExecuteGenericTestTable(t, confirmationTable) @@ -46,7 +47,7 @@ func (suite *OcppV16TestSuite) TestDiagnosticsStatusNotificationE2EMocked() { assert.Equal(t, status, request.Status) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.centralSystem.SetFirmwareManagementHandler(firmwareListener) + suite.centralSystem.SetFirmwareManagementHandler(&firmwareListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath") diff --git a/ocpp1.6_test/firmware_status_notification_test.go b/ocpp1.6_test/firmware_status_notification_test.go index bdd467be..5d66c7a6 100644 --- a/ocpp1.6_test/firmware_status_notification_test.go +++ b/ocpp1.6_test/firmware_status_notification_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -11,7 +12,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {firmware.FirmwareStatusNotificationRequest{Status: firmware.FirmwareStatusDownloaded}, true}, {firmware.FirmwareStatusNotificationRequest{}, false}, {firmware.FirmwareStatusNotificationRequest{Status: "invalidFirmwareStatus"}, false}, @@ -21,7 +22,7 @@ func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationRequestValidation() func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {firmware.FirmwareStatusNotificationConfirmation{}, true}, } ExecuteGenericTestTable(t, confirmationTable) @@ -46,7 +47,7 @@ func (suite *OcppV16TestSuite) TestFirmwareStatusNotificationE2EMocked() { assert.Equal(t, status, request.Status) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.centralSystem.SetFirmwareManagementHandler(firmwareListener) + suite.centralSystem.SetFirmwareManagementHandler(&firmwareListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath") diff --git a/ocpp1.6_test/get_composite_schedule_test.go b/ocpp1.6_test/get_composite_schedule_test.go index 8f32178f..435e98c0 100644 --- a/ocpp1.6_test/get_composite_schedule_test.go +++ b/ocpp1.6_test/get_composite_schedule_test.go @@ -2,18 +2,19 @@ package ocpp16_test import ( "fmt" + "time" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging" "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "time" ) // Test func (suite *OcppV16TestSuite) TestGetCompositeScheduleRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {smartcharging.GetCompositeScheduleRequest{ConnectorId: 1, Duration: 600, ChargingRateUnit: types.ChargingRateUnitWatts}, true}, {smartcharging.GetCompositeScheduleRequest{ConnectorId: 1, Duration: 600}, true}, {smartcharging.GetCompositeScheduleRequest{ConnectorId: 1}, true}, @@ -28,7 +29,7 @@ func (suite *OcppV16TestSuite) TestGetCompositeScheduleRequestValidation() { func (suite *OcppV16TestSuite) TestGetCompositeScheduleConfirmationValidation() { t := suite.T() chargingSchedule := types.NewChargingSchedule(types.ChargingRateUnitWatts, types.NewChargingSchedulePeriod(0, 10.0)) - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1), ScheduleStart: types.NewDateTime(time.Now()), ChargingSchedule: chargingSchedule}, true}, {smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1), ScheduleStart: types.NewDateTime(time.Now())}, true}, {smartcharging.GetCompositeScheduleConfirmation{Status: smartcharging.GetCompositeScheduleStatusAccepted, ConnectorId: newInt(1)}, true}, @@ -75,7 +76,7 @@ func (suite *OcppV16TestSuite) TestGetCompositeScheduleE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetSmartChargingHandler(smartChargingListener) + suite.chargePoint.SetSmartChargingHandler(&smartChargingListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/get_diagnostics_test.go b/ocpp1.6_test/get_diagnostics_test.go index 0672211b..6d4d7207 100644 --- a/ocpp1.6_test/get_diagnostics_test.go +++ b/ocpp1.6_test/get_diagnostics_test.go @@ -14,7 +14,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestGetDiagnosticsRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10), StartTime: types.NewDateTime(time.Now()), StopTime: types.NewDateTime(time.Now())}, true}, {firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10), StartTime: types.NewDateTime(time.Now())}, true}, {firmware.GetDiagnosticsRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10)}, true}, @@ -30,7 +30,7 @@ func (suite *OcppV16TestSuite) TestGetDiagnosticsRequestValidation() { func (suite *OcppV16TestSuite) TestGetDiagnosticsConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {firmware.GetDiagnosticsConfirmation{FileName: "someFileName"}, true}, {firmware.GetDiagnosticsConfirmation{FileName: ""}, true}, {firmware.GetDiagnosticsConfirmation{}, true}, @@ -71,7 +71,7 @@ func (suite *OcppV16TestSuite) TestGetDiagnosticsE2EMocked() { assertDateTimeEquality(t, *stopTime, *request.StopTime) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) - suite.chargePoint.SetFirmwareManagementHandler(firmwareListener) + suite.chargePoint.SetFirmwareManagementHandler(&firmwareListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath") diff --git a/ocpp1.6_test/get_local_list_version_test.go b/ocpp1.6_test/get_local_list_version_test.go index 39d31cd2..287e36d4 100644 --- a/ocpp1.6_test/get_local_list_version_test.go +++ b/ocpp1.6_test/get_local_list_version_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/localauth" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -11,7 +12,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestGetLocalListVersionRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {localauth.GetLocalListVersionRequest{}, true}, } ExecuteGenericTestTable(t, requestTable) @@ -19,7 +20,7 @@ func (suite *OcppV16TestSuite) TestGetLocalListVersionRequestValidation() { func (suite *OcppV16TestSuite) TestGetLocalListVersionConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {localauth.GetLocalListVersionConfirmation{ListVersion: 1}, true}, {localauth.GetLocalListVersionConfirmation{ListVersion: 0}, true}, {localauth.GetLocalListVersionConfirmation{}, true}, @@ -47,7 +48,7 @@ func (suite *OcppV16TestSuite) TestGetLocalListVersionE2EMocked() { require.True(t, ok) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) - suite.chargePoint.SetLocalAuthListHandler(localAuthListListener) + suite.chargePoint.SetLocalAuthListHandler(&localAuthListListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath") diff --git a/ocpp1.6_test/ocpp16_test.go b/ocpp1.6_test/ocpp16_test.go index 137fa7b9..4a826bd1 100644 --- a/ocpp1.6_test/ocpp16_test.go +++ b/ocpp1.6_test/ocpp16_test.go @@ -179,34 +179,26 @@ type MockFeature struct { mock.Mock } -func (f MockFeature) GetFeatureName() string { +func (f *MockFeature) GetFeatureName() string { return MockFeatureName } -func (f MockFeature) GetRequestType() reflect.Type { +func (f *MockFeature) GetRequestType() reflect.Type { return reflect.TypeOf(MockRequest{}) } -func (f MockFeature) GetResponseType() reflect.Type { +func (f *MockFeature) GetResponseType() reflect.Type { return reflect.TypeOf(MockConfirmation{}) } -func (r MockRequest) GetFeatureName() string { +func (r *MockRequest) GetFeatureName() string { return MockFeatureName } -func (c MockConfirmation) GetFeatureName() string { +func (c *MockConfirmation) GetFeatureName() string { return MockFeatureName } -func newMockRequest(value string) *MockRequest { - return &MockRequest{MockValue: value} -} - -func newMockConfirmation(value string) *MockConfirmation { - return &MockConfirmation{MockValue: value} -} - // ---------------------- MOCK CS CORE LISTENER ---------------------- type MockCentralSystemCoreListener struct { mock.Mock @@ -337,13 +329,13 @@ type MockChargePointLocalAuthListListener struct { mock.Mock } -func (localAuthListListener MockChargePointLocalAuthListListener) OnGetLocalListVersion(request *localauth.GetLocalListVersionRequest) (confirmation *localauth.GetLocalListVersionConfirmation, err error) { +func (localAuthListListener *MockChargePointLocalAuthListListener) OnGetLocalListVersion(request *localauth.GetLocalListVersionRequest) (confirmation *localauth.GetLocalListVersionConfirmation, err error) { args := localAuthListListener.MethodCalled("OnGetLocalListVersion", request) conf := args.Get(0).(*localauth.GetLocalListVersionConfirmation) return conf, args.Error(1) } -func (localAuthListListener MockChargePointLocalAuthListListener) OnSendLocalList(request *localauth.SendLocalListRequest) (confirmation *localauth.SendLocalListConfirmation, err error) { +func (localAuthListListener *MockChargePointLocalAuthListListener) OnSendLocalList(request *localauth.SendLocalListRequest) (confirmation *localauth.SendLocalListConfirmation, err error) { args := localAuthListListener.MethodCalled("OnSendLocalList", request) conf := args.Get(0).(*localauth.SendLocalListConfirmation) return conf, args.Error(1) @@ -354,13 +346,13 @@ type MockCentralSystemFirmwareManagementListener struct { mock.Mock } -func (firmwareListener MockCentralSystemFirmwareManagementListener) OnDiagnosticsStatusNotification(chargePointId string, request *firmware.DiagnosticsStatusNotificationRequest) (confirmation *firmware.DiagnosticsStatusNotificationConfirmation, err error) { +func (firmwareListener *MockCentralSystemFirmwareManagementListener) OnDiagnosticsStatusNotification(chargePointId string, request *firmware.DiagnosticsStatusNotificationRequest) (confirmation *firmware.DiagnosticsStatusNotificationConfirmation, err error) { args := firmwareListener.MethodCalled("OnDiagnosticsStatusNotification", chargePointId, request) conf := args.Get(0).(*firmware.DiagnosticsStatusNotificationConfirmation) return conf, args.Error(1) } -func (firmwareListener MockCentralSystemFirmwareManagementListener) OnFirmwareStatusNotification(chargePointId string, request *firmware.FirmwareStatusNotificationRequest) (confirmation *firmware.FirmwareStatusNotificationConfirmation, err error) { +func (firmwareListener *MockCentralSystemFirmwareManagementListener) OnFirmwareStatusNotification(chargePointId string, request *firmware.FirmwareStatusNotificationRequest) (confirmation *firmware.FirmwareStatusNotificationConfirmation, err error) { args := firmwareListener.MethodCalled("OnFirmwareStatusNotification", chargePointId, request) conf := args.Get(0).(*firmware.FirmwareStatusNotificationConfirmation) return conf, args.Error(1) @@ -371,13 +363,13 @@ type MockChargePointFirmwareManagementListener struct { mock.Mock } -func (firmwareListener MockChargePointFirmwareManagementListener) OnGetDiagnostics(request *firmware.GetDiagnosticsRequest) (confirmation *firmware.GetDiagnosticsConfirmation, err error) { +func (firmwareListener *MockChargePointFirmwareManagementListener) OnGetDiagnostics(request *firmware.GetDiagnosticsRequest) (confirmation *firmware.GetDiagnosticsConfirmation, err error) { args := firmwareListener.MethodCalled("OnGetDiagnostics", request) conf := args.Get(0).(*firmware.GetDiagnosticsConfirmation) return conf, args.Error(1) } -func (firmwareListener MockChargePointFirmwareManagementListener) OnUpdateFirmware(request *firmware.UpdateFirmwareRequest) (confirmation *firmware.UpdateFirmwareConfirmation, err error) { +func (firmwareListener *MockChargePointFirmwareManagementListener) OnUpdateFirmware(request *firmware.UpdateFirmwareRequest) (confirmation *firmware.UpdateFirmwareConfirmation, err error) { args := firmwareListener.MethodCalled("OnUpdateFirmware", request) conf := args.Get(0).(*firmware.UpdateFirmwareConfirmation) return conf, args.Error(1) @@ -393,13 +385,13 @@ type MockChargePointReservationListener struct { mock.Mock } -func (reservationListener MockChargePointReservationListener) OnReserveNow(request *reservation.ReserveNowRequest) (confirmation *reservation.ReserveNowConfirmation, err error) { +func (reservationListener *MockChargePointReservationListener) OnReserveNow(request *reservation.ReserveNowRequest) (confirmation *reservation.ReserveNowConfirmation, err error) { args := reservationListener.MethodCalled("OnReserveNow", request) conf := args.Get(0).(*reservation.ReserveNowConfirmation) return conf, args.Error(1) } -func (reservationListener MockChargePointReservationListener) OnCancelReservation(request *reservation.CancelReservationRequest) (confirmation *reservation.CancelReservationConfirmation, err error) { +func (reservationListener *MockChargePointReservationListener) OnCancelReservation(request *reservation.CancelReservationRequest) (confirmation *reservation.CancelReservationConfirmation, err error) { args := reservationListener.MethodCalled("OnCancelReservation", request) conf := args.Get(0).(*reservation.CancelReservationConfirmation) return conf, args.Error(1) @@ -415,7 +407,7 @@ type MockChargePointRemoteTriggerListener struct { mock.Mock } -func (remoteTriggerListener MockChargePointRemoteTriggerListener) OnTriggerMessage(request *remotetrigger.TriggerMessageRequest) (confirmation *remotetrigger.TriggerMessageConfirmation, err error) { +func (remoteTriggerListener *MockChargePointRemoteTriggerListener) OnTriggerMessage(request *remotetrigger.TriggerMessageRequest) (confirmation *remotetrigger.TriggerMessageConfirmation, err error) { args := remoteTriggerListener.MethodCalled("OnTriggerMessage", request) conf := args.Get(0).(*remotetrigger.TriggerMessageConfirmation) return conf, args.Error(1) @@ -431,19 +423,19 @@ type MockChargePointSmartChargingListener struct { mock.Mock } -func (smartChargingListener MockChargePointSmartChargingListener) OnSetChargingProfile(request *smartcharging.SetChargingProfileRequest) (confirmation *smartcharging.SetChargingProfileConfirmation, err error) { +func (smartChargingListener *MockChargePointSmartChargingListener) OnSetChargingProfile(request *smartcharging.SetChargingProfileRequest) (confirmation *smartcharging.SetChargingProfileConfirmation, err error) { args := smartChargingListener.MethodCalled("OnSetChargingProfile", request) conf := args.Get(0).(*smartcharging.SetChargingProfileConfirmation) return conf, args.Error(1) } -func (smartChargingListener MockChargePointSmartChargingListener) OnClearChargingProfile(request *smartcharging.ClearChargingProfileRequest) (confirmation *smartcharging.ClearChargingProfileConfirmation, err error) { +func (smartChargingListener *MockChargePointSmartChargingListener) OnClearChargingProfile(request *smartcharging.ClearChargingProfileRequest) (confirmation *smartcharging.ClearChargingProfileConfirmation, err error) { args := smartChargingListener.MethodCalled("OnClearChargingProfile", request) conf := args.Get(0).(*smartcharging.ClearChargingProfileConfirmation) return conf, args.Error(1) } -func (smartChargingListener MockChargePointSmartChargingListener) OnGetCompositeSchedule(request *smartcharging.GetCompositeScheduleRequest) (confirmation *smartcharging.GetCompositeScheduleConfirmation, err error) { +func (smartChargingListener *MockChargePointSmartChargingListener) OnGetCompositeSchedule(request *smartcharging.GetCompositeScheduleRequest) (confirmation *smartcharging.GetCompositeScheduleConfirmation, err error) { args := smartChargingListener.MethodCalled("OnGetCompositeSchedule", request) conf := args.Get(0).(*smartcharging.GetCompositeScheduleConfirmation) return conf, args.Error(1) diff --git a/ocpp1.6_test/reserve_now_test.go b/ocpp1.6_test/reserve_now_test.go index d7dc3604..5702824b 100644 --- a/ocpp1.6_test/reserve_now_test.go +++ b/ocpp1.6_test/reserve_now_test.go @@ -2,18 +2,19 @@ package ocpp16_test import ( "fmt" + "time" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/reservation" "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "time" ) // Test func (suite *OcppV16TestSuite) TestReserveNowRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {reservation.ReserveNowRequest{ConnectorId: 1, ExpiryDate: types.NewDateTime(time.Now()), IdTag: "12345", ReservationId: 42, ParentIdTag: "9999"}, true}, {reservation.ReserveNowRequest{ConnectorId: 1, ExpiryDate: types.NewDateTime(time.Now()), IdTag: "12345", ReservationId: 42}, true}, {reservation.ReserveNowRequest{ExpiryDate: types.NewDateTime(time.Now()), IdTag: "12345", ReservationId: 42}, true}, @@ -30,7 +31,7 @@ func (suite *OcppV16TestSuite) TestReserveNowRequestValidation() { func (suite *OcppV16TestSuite) TestReserveNowConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {reservation.ReserveNowConfirmation{Status: reservation.ReservationStatusAccepted}, true}, {reservation.ReserveNowConfirmation{Status: "invalidReserveNowStatus"}, false}, {reservation.ReserveNowConfirmation{}, false}, @@ -69,7 +70,7 @@ func (suite *OcppV16TestSuite) TestReserveNowE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetReservationHandler(reservationListener) + suite.chargePoint.SetReservationHandler(&reservationListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/send_local_list_test.go b/ocpp1.6_test/send_local_list_test.go index 4c1650d3..eff186d0 100644 --- a/ocpp1.6_test/send_local_list_test.go +++ b/ocpp1.6_test/send_local_list_test.go @@ -2,12 +2,13 @@ package ocpp16_test import ( "fmt" + "time" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/localauth" "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "time" ) // Test @@ -23,7 +24,7 @@ func (suite *OcppV16TestSuite) TestSendLocalListRequestValidation() { ParentIdTag: "000000", Status: "invalidStatus", }} - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {localauth.SendLocalListRequest{UpdateType: localauth.UpdateTypeDifferential, ListVersion: 1, LocalAuthorizationList: []localauth.AuthorizationData{localAuthEntry}}, true}, {localauth.SendLocalListRequest{UpdateType: localauth.UpdateTypeDifferential, ListVersion: 1, LocalAuthorizationList: []localauth.AuthorizationData{}}, true}, {localauth.SendLocalListRequest{UpdateType: localauth.UpdateTypeDifferential, ListVersion: 1}, true}, @@ -40,7 +41,7 @@ func (suite *OcppV16TestSuite) TestSendLocalListRequestValidation() { func (suite *OcppV16TestSuite) TestSendLocalListConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {localauth.SendLocalListConfirmation{Status: localauth.UpdateStatusAccepted}, true}, {localauth.SendLocalListConfirmation{Status: "invalidStatus"}, false}, {localauth.SendLocalListConfirmation{}, false}, @@ -82,7 +83,7 @@ func (suite *OcppV16TestSuite) TestSendLocalListE2EMocked() { assertDateTimeEquality(t, *localAuthEntry.IdTagInfo.ExpiryDate, *request.LocalAuthorizationList[0].IdTagInfo.ExpiryDate) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) - suite.chargePoint.SetLocalAuthListHandler(localAuthListListener) + suite.chargePoint.SetLocalAuthListHandler(&localAuthListListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath") diff --git a/ocpp1.6_test/set_charging_profile_test.go b/ocpp1.6_test/set_charging_profile_test.go index 0a84f10e..199dcc87 100644 --- a/ocpp1.6_test/set_charging_profile_test.go +++ b/ocpp1.6_test/set_charging_profile_test.go @@ -15,7 +15,7 @@ func (suite *OcppV16TestSuite) TestSetChargingProfileRequestValidation() { t := suite.T() chargingSchedule := types.NewChargingSchedule(types.ChargingRateUnitWatts, types.NewChargingSchedulePeriod(0, 10.0)) chargingProfile := types.NewChargingProfile(1, 1, types.ChargingProfilePurposeChargePointMaxProfile, types.ChargingProfileKindAbsolute, chargingSchedule) - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {smartcharging.SetChargingProfileRequest{ConnectorId: 1, ChargingProfile: chargingProfile}, true}, {smartcharging.SetChargingProfileRequest{ChargingProfile: chargingProfile}, true}, {smartcharging.SetChargingProfileRequest{}, false}, @@ -27,7 +27,7 @@ func (suite *OcppV16TestSuite) TestSetChargingProfileRequestValidation() { func (suite *OcppV16TestSuite) TestSetChargingProfileConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {smartcharging.SetChargingProfileConfirmation{Status: smartcharging.ChargingProfileStatusAccepted}, true}, {smartcharging.SetChargingProfileConfirmation{Status: "invalidChargingProfileStatus"}, false}, {smartcharging.SetChargingProfileConfirmation{}, false}, @@ -91,7 +91,7 @@ func (suite *OcppV16TestSuite) TestSetChargingProfileE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetSmartChargingHandler(smartChargingListener) + suite.chargePoint.SetSmartChargingHandler(&smartChargingListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/trigger_message_test.go b/ocpp1.6_test/trigger_message_test.go index 48f8dc54..130394fb 100644 --- a/ocpp1.6_test/trigger_message_test.go +++ b/ocpp1.6_test/trigger_message_test.go @@ -2,6 +2,7 @@ package ocpp16_test import ( "fmt" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" "github.com/lorenzodonini/ocpp-go/ocpp1.6/remotetrigger" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ import ( // Test func (suite *OcppV16TestSuite) TestTriggerMessageRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {remotetrigger.TriggerMessageRequest{RequestedMessage: core.StatusNotificationFeatureName, ConnectorId: newInt(1)}, true}, {remotetrigger.TriggerMessageRequest{RequestedMessage: core.StatusNotificationFeatureName}, true}, {remotetrigger.TriggerMessageRequest{}, false}, @@ -24,7 +25,7 @@ func (suite *OcppV16TestSuite) TestTriggerMessageRequestValidation() { func (suite *OcppV16TestSuite) TestTriggerMessageConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {remotetrigger.TriggerMessageConfirmation{Status: remotetrigger.TriggerMessageStatusAccepted}, true}, {remotetrigger.TriggerMessageConfirmation{Status: "invalidTriggerMessageStatus"}, false}, {remotetrigger.TriggerMessageConfirmation{}, false}, @@ -55,7 +56,7 @@ func (suite *OcppV16TestSuite) TestTriggerMessageE2EMocked() { }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) - suite.chargePoint.SetRemoteTriggerHandler(remoteTriggerListener) + suite.chargePoint.SetRemoteTriggerHandler(&remoteTriggerListener) // Run Test suite.centralSystem.Start(8887, "somePath") err := suite.chargePoint.Start(wsUrl) diff --git a/ocpp1.6_test/update_firmware_test.go b/ocpp1.6_test/update_firmware_test.go index d2ef1130..6458725f 100644 --- a/ocpp1.6_test/update_firmware_test.go +++ b/ocpp1.6_test/update_firmware_test.go @@ -2,18 +2,19 @@ package ocpp16_test import ( "fmt" + "time" + "github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware" "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "time" ) // Test func (suite *OcppV16TestSuite) TestUpdateFirmwareRequestValidation() { t := suite.T() - var requestTable = []GenericTestEntry{ + requestTable := []GenericTestEntry{ {firmware.UpdateFirmwareRequest{Location: "ftp:some/path", Retries: newInt(10), RetryInterval: newInt(10), RetrieveDate: types.NewDateTime(time.Now())}, true}, {firmware.UpdateFirmwareRequest{Location: "ftp:some/path", Retries: newInt(10), RetrieveDate: types.NewDateTime(time.Now())}, true}, {firmware.UpdateFirmwareRequest{Location: "ftp:some/path", RetrieveDate: types.NewDateTime(time.Now())}, true}, @@ -28,7 +29,7 @@ func (suite *OcppV16TestSuite) TestUpdateFirmwareRequestValidation() { func (suite *OcppV16TestSuite) TestUpdateFirmwareConfirmationValidation() { t := suite.T() - var confirmationTable = []GenericTestEntry{ + confirmationTable := []GenericTestEntry{ {firmware.UpdateFirmwareConfirmation{}, true}, } ExecuteGenericTestTable(t, confirmationTable) @@ -62,7 +63,7 @@ func (suite *OcppV16TestSuite) TestUpdateFirmwareE2EMocked() { assertDateTimeEquality(t, *retrieveDate, *request.RetrieveDate) }) setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true}) - suite.chargePoint.SetFirmwareManagementHandler(firmwareListener) + suite.chargePoint.SetFirmwareManagementHandler(&firmwareListener) setupDefaultChargePointHandlers(suite, nil, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true}) // Run Test suite.centralSystem.Start(8887, "somePath")