Skip to content
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

Allow empty idTag #17

Merged
merged 1 commit into from
Mar 6, 2024
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
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
Loading