Skip to content

Commit

Permalink
Merge pull request #17 from grid-x/fix/allow-empty-idTag-INTE-1856
Browse files Browse the repository at this point in the history
Allow empty idTag
  • Loading branch information
hsteidl committed Mar 6, 2024
2 parents a095032 + 6b715c1 commit a23b2e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions ocpp1.6/core/authorize.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package core

import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"reflect"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)

// -------------------- Authorize (CP -> CS) --------------------
Expand All @@ -11,7 +12,7 @@ const AuthorizeFeatureName = "Authorize"

// The field definition of the Authorize request payload sent by the Charge Point to the Central System.
type AuthorizeRequest struct {
IdTag string `json:"idTag" validate:"required,max=20"`
IdTag string `json:"idTag" validate:"omitempty,max=20"`
}

// This field definition of the Authorize confirmation payload, sent by the Charge Point to the Central System in response to an AuthorizeRequest.
Expand Down
5 changes: 3 additions & 2 deletions ocpp1.6/core/start_transaction.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package core

import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"reflect"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)

// -------------------- Start Transaction (CP -> CS) --------------------
Expand All @@ -12,7 +13,7 @@ const StartTransactionFeatureName = "StartTransaction"
// This field definition of the StartTransactionRequest payload sent by the Charge Point to the Central System.
type StartTransactionRequest struct {
ConnectorId int `json:"connectorId" validate:"gt=0"`
IdTag string `json:"idTag" validate:"required,max=20"`
IdTag string `json:"idTag" validate:"omitempty,max=20"`
MeterStart int `json:"meterStart" validate:"gte=0"`
ReservationId *int `json:"reservationId,omitempty" validate:"omitempty"`
Timestamp *types.DateTime `json:"timestamp" validate:"required"`
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import (
"fmt"
"time"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)

// Test
func (suite *OcppV16TestSuite) TestAuthorizeRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
{core.AuthorizeRequest{IdTag: "12345"}, true},
{core.AuthorizeRequest{}, false},
{core.AuthorizeRequest{}, true},
{core.AuthorizeRequest{IdTag: ">20.................."}, false},
}
ExecuteGenericTestTable(t, requestTable)
Expand Down
7 changes: 4 additions & 3 deletions ocpp1.6_test/start_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"time"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)

// Test
Expand All @@ -22,7 +23,7 @@ func (suite *OcppV16TestSuite) TestStartTransactionRequestValidation() {
{core.StartTransactionRequest{ConnectorId: -1, IdTag: "12345", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false},
{core.StartTransactionRequest{ConnectorId: 1, IdTag: ">20..................", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false},
{core.StartTransactionRequest{IdTag: "12345", MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false},
{core.StartTransactionRequest{ConnectorId: 1, MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, false},
{core.StartTransactionRequest{ConnectorId: 1, MeterStart: 100, Timestamp: types.NewDateTime(time.Now())}, true},
{core.StartTransactionRequest{ConnectorId: 1, IdTag: "12345", MeterStart: 100}, false},
}
ExecuteGenericTestTable(t, requestTable)
Expand Down

0 comments on commit a23b2e5

Please sign in to comment.