From 467a7f8dab4efd5edc3b286c4f9478c79955ef35 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 2 May 2025 10:40:32 +0200 Subject: [PATCH] chore: fix tests --- charger/plugchoice.go | 18 +++++++----------- charger/template_test.go | 5 +++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/charger/plugchoice.go b/charger/plugchoice.go index a83d679d3..f087a4c04 100644 --- a/charger/plugchoice.go +++ b/charger/plugchoice.go @@ -18,6 +18,7 @@ package charger // SOFTWARE. import ( + "errors" "fmt" "net/http" "strconv" @@ -68,12 +69,7 @@ func NewPlugchoiceFromConfig(other map[string]interface{}) (api.Charger, error) return nil, err } - // If both are provided, Identity takes precedence - if cc.Identity != "" || cc.UUID != "" { - return NewPlugchoice(cc.URI, cc.UUID, cc.Identity, cc.Connector, cc.Token, cc.Cache) - } - - return nil, fmt.Errorf("either identity or uuid must be provided") + return NewPlugchoice(cc.URI, cc.UUID, cc.Identity, cc.Connector, cc.Token, cc.Cache) } // NewPlugchoice creates a Plugchoice charger @@ -92,6 +88,11 @@ func NewPlugchoice(uri, uuid, identity string, connector int, token string, cach } } + // If both are provided, Identity takes precedence + if identity == "" && uuid == "" { + return nil, errors.New("either identity or uuid are required") + } + // If identity is provided but no UUID, try to find the UUID if uuid == "" && identity != "" { var err error @@ -101,11 +102,6 @@ func NewPlugchoice(uri, uuid, identity string, connector int, token string, cach } } - // If we still don't have a UUID, return an error - if uuid == "" { - return nil, fmt.Errorf("either uuid or identity must be provided") - } - if !sponsor.IsAuthorized() { return nil, api.ErrSponsorRequired } diff --git a/charger/template_test.go b/charger/template_test.go index 884d0b006..2d21aaf62 100644 --- a/charger/template_test.go +++ b/charger/template_test.go @@ -32,8 +32,9 @@ var acceptable = []string{ "sponsorship required, see https://docs.evcc.io/docs/sponsorship", "eebus not configured", "context deadline exceeded", - "timeout", // ocpp - "must have uri and password", // Wattpilot + "timeout", // ocpp + "must have uri and password", // Wattpilot + "either identity or uuid are required", // Plugchoice } func TestTemplates(t *testing.T) {