From 6289e8ede54e88bb7b977306085b6b53997ea6bf Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Wed, 11 Oct 2023 18:04:07 +0200 Subject: [PATCH 1/7] make unused template tests run in parallel --- util/templates/render_testing.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index af96b7ee1c..a290296bd3 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -56,6 +56,8 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values usages := tmpl.Usages() if len(usages) == 0 { + t.Parallel() + test(t, tmpl, values, func(values map[string]interface{}) { instantiate(t, values) }) From 415b6d23c2cddfa926c01c498c9e762943331d4b Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Wed, 25 Oct 2023 20:51:59 +0200 Subject: [PATCH 2/7] revert change of test, change default uri to localhost --- util/templates/defaults.yaml | 4 ++-- util/templates/render_testing.go | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/util/templates/defaults.yaml b/util/templates/defaults.yaml index d6a581fd68..66bdb4b979 100644 --- a/util/templates/defaults.yaml +++ b/util/templates/defaults.yaml @@ -44,7 +44,7 @@ params: help: de: IP-Adresse oder Hostname en: IP address or hostname - example: 192.0.2.2 + example: localhost - name: ip description: de: IP-Adresse @@ -52,7 +52,7 @@ params: help: de: IP-Adresse en: IP address - example: 192.0.2.2 + example: 127.0.0.1 - name: port description: de: Port diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index a290296bd3..af96b7ee1c 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -56,8 +56,6 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values usages := tmpl.Usages() if len(usages) == 0 { - t.Parallel() - test(t, tmpl, values, func(values map[string]interface{}) { instantiate(t, values) }) From c392e20b833a3533978300a46b625b1f926de57b Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Thu, 26 Oct 2023 20:25:08 +0200 Subject: [PATCH 3/7] revert example changes, introduce defaults --- util/templates/defaults.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/templates/defaults.yaml b/util/templates/defaults.yaml index 66bdb4b979..41186aced9 100644 --- a/util/templates/defaults.yaml +++ b/util/templates/defaults.yaml @@ -44,7 +44,8 @@ params: help: de: IP-Adresse oder Hostname en: IP address or hostname - example: localhost + default: localhost + example: 192.0.2.2 - name: ip description: de: IP-Adresse @@ -52,7 +53,8 @@ params: help: de: IP-Adresse en: IP address - example: 127.0.0.1 + default: 127.0.0.1 + example: 192.0.2.2 - name: port description: de: Port From 64665267115757d3fac00aece5bbda7ad3e35819 Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Mon, 30 Oct 2023 21:29:13 +0100 Subject: [PATCH 4/7] revert changes to defaults, override ip in test code --- util/templates/defaults.yaml | 2 -- util/templates/render_testing.go | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/util/templates/defaults.yaml b/util/templates/defaults.yaml index 41186aced9..d6a581fd68 100644 --- a/util/templates/defaults.yaml +++ b/util/templates/defaults.yaml @@ -44,7 +44,6 @@ params: help: de: IP-Adresse oder Hostname en: IP address or hostname - default: localhost example: 192.0.2.2 - name: ip description: @@ -53,7 +52,6 @@ params: help: de: IP-Adresse en: IP address - default: 127.0.0.1 example: 192.0.2.2 - name: port description: diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index af96b7ee1c..2b7a15fc3a 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -54,6 +54,9 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values tmpl.ModbusValues(TemplateRenderModeUnitTest, values) } + // https://github.com/evcc-io/evcc/pull/10272 - override example IP (192.0.2.2) + values["host"] = "localhost" + usages := tmpl.Usages() if len(usages) == 0 { test(t, tmpl, values, func(values map[string]interface{}) { From 995c87cb6500264e9d9351bd3344172885b6ac0f Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 1 Nov 2023 23:10:10 +0100 Subject: [PATCH 5/7] Add accaptable errors --- charger/openwb.go | 2 +- charger/template_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/charger/openwb.go b/charger/openwb.go index ff257ca311..eecc569e6f 100644 --- a/charger/openwb.go +++ b/charger/openwb.go @@ -77,7 +77,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p // check if loadpoint configured configured := boolG(fmt.Sprintf("%s/lp/%d/%s", topic, id, openwb.ConfiguredTopic)) if isConfigured, err := configured(); err != nil || !isConfigured { - return nil, fmt.Errorf("openWB loadpoint %d is not configured", id) + return nil, fmt.Errorf("loadpoint %d is not configured", id) } // adapt plugged/charging to status diff --git a/charger/template_test.go b/charger/template_test.go index 6ef450850d..d33ff9efc9 100644 --- a/charger/template_test.go +++ b/charger/template_test.go @@ -17,8 +17,10 @@ var acceptable = []string{ "hciconfig provided no response", "connect: no route to host", "connect: connection refused", + "connector already registered: 1", // ocpp "error connecting: Network Error", "i/o timeout", + "loadpoint 1 is not configured", // openWB "recv timeout", "(Client.Timeout exceeded while awaiting headers)", "can only have either uri or device", // modbus From 6131de0a448663ea85e5bb3556621ab7f7e522e1 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 1 Nov 2023 23:15:54 +0100 Subject: [PATCH 6/7] Allow running all template tests in parallel --- util/templates/render_testing.go | 80 ++++++++++++++++---------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index 2b7a15fc3a..110e8d0e9c 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -35,54 +35,56 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values for _, tmpl := range ByClass(class) { tmpl := tmpl - t.Run(tmpl.Template, func(t *testing.T) { - // set default values for all params - values := tmpl.Defaults(TemplateRenderModeUnitTest) - - // set the template value which is needed for rendering - values["template"] = tmpl.Template - - // set modbus default test values - if values[ParamModbus] != nil { - modbusChoices := tmpl.ModbusChoices() - // we only test one modbus setup - if slices.Contains(modbusChoices, ModbusChoiceTCPIP) { - values[ModbusKeyTCPIP] = true - } else { - values[ModbusKeyRS485TCPIP] = true - } - tmpl.ModbusValues(TemplateRenderModeUnitTest, values) + // set default values for all params + values := tmpl.Defaults(TemplateRenderModeUnitTest) + + // set the template value which is needed for rendering + values["template"] = tmpl.Template + + // set modbus default test values + if values[ParamModbus] != nil { + modbusChoices := tmpl.ModbusChoices() + // we only test one modbus setup + if slices.Contains(modbusChoices, ModbusChoiceTCPIP) { + values[ModbusKeyTCPIP] = true + } else { + values[ModbusKeyRS485TCPIP] = true } + tmpl.ModbusValues(TemplateRenderModeUnitTest, values) + } - // https://github.com/evcc-io/evcc/pull/10272 - override example IP (192.0.2.2) - values["host"] = "localhost" + // https://github.com/evcc-io/evcc/pull/10272 - override example IP (192.0.2.2) + values["host"] = "localhost" + + usages := tmpl.Usages() + if len(usages) == 0 { + t.Run(tmpl.Template, func(t *testing.T) { + t.Parallel() - usages := tmpl.Usages() - if len(usages) == 0 { test(t, tmpl, values, func(values map[string]interface{}) { instantiate(t, values) }) + }) + + return + } - return + for _, u := range usages { + // create a copy of the map for parallel execution + usageValues := make(map[string]interface{}, len(values)+1) + if err := copier.Copy(&usageValues, values); err != nil { + panic(err) } + usageValues[ParamUsage] = u - for _, u := range usages { - // create a copy of the map for parallel execution - usageValues := make(map[string]interface{}, len(values)+1) - if err := copier.Copy(&usageValues, values); err != nil { - panic(err) - } - usageValues[ParamUsage] = u - - // subtest for each usage - t.Run(u, func(t *testing.T) { - t.Parallel() - - test(t, tmpl, usageValues, func(values map[string]interface{}) { - instantiate(t, values) - }) + // subtest for each usage + t.Run(u, func(t *testing.T) { + t.Parallel() + + test(t, tmpl, usageValues, func(values map[string]interface{}) { + instantiate(t, values) }) - } - }) + }) + } } } From 4bc25cab494ea940d636cadf984a06357d2a4d41 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 1 Nov 2023 23:25:33 +0100 Subject: [PATCH 7/7] Align --- util/templates/render_testing.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index 110e8d0e9c..22baff0d47 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -38,9 +38,6 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values // set default values for all params values := tmpl.Defaults(TemplateRenderModeUnitTest) - // set the template value which is needed for rendering - values["template"] = tmpl.Template - // set modbus default test values if values[ParamModbus] != nil { modbusChoices := tmpl.ModbusChoices() @@ -53,6 +50,8 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values tmpl.ModbusValues(TemplateRenderModeUnitTest, values) } + // set the template value which is needed for rendering + values["template"] = tmpl.Template // https://github.com/evcc-io/evcc/pull/10272 - override example IP (192.0.2.2) values["host"] = "localhost"