8000 fix(issue-253): fix all go vet errors by frednesto · Pull Request #254 · lorenzodonini/ocpp-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(issue-253): fix all go vet errors #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ocpp1.6_test/cancel_reservation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/clear_charging_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions ocpp1.6_test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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)
}
7 changes: 4 additions & 3 deletions ocpp1.6_test/diagnostics_status_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand All @@ -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)
Expand All @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/firmware_status_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand All @@ -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)
Expand All @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions ocpp1.6_test/get_composite_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ocpp1.6_test/get_diagnostics_test.go
1005C
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/get_local_list_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -11,15 +12,15 @@ import (
// Test
func (suite *OcppV16TestSuite) TestGetLocalListVersionRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
requestTable := []GenericTestEntry{
{localauth.GetLocalListVersionRequest{}, true},
}
ExecuteGenericTestTable(t, requestTable)
}

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},
Expand Down Expand Up @@ -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")
Expand Down
Loading
0