diff --git a/templates/definition/charger/fritzdect.yaml b/templates/definition/charger/fritzdect.yaml index afdb93084..d39fd418c 100644 --- a/templates/definition/charger/fritzdect.yaml +++ b/templates/definition/charger/fritzdect.yaml @@ -26,5 +26,5 @@ render: | uri: {{ .uri }} user: {{ .user }} password: {{ .password }} - ain: "{{ .ain }}" # switch actor identification number without blanks (see AIN number on switch sticker) + ain: {{ .ain }} # switch actor identification number without blanks (see AIN number on switch sticker) standbypower: {{ .standbypower }} diff --git a/templates/definition/meter/fritzdect.yaml b/templates/definition/meter/fritzdect.yaml index 5d1760ada..3d8c8e980 100644 --- a/templates/definition/meter/fritzdect.yaml +++ b/templates/definition/meter/fritzdect.yaml @@ -26,4 +26,4 @@ render: | uri: {{ .uri }} user: {{ .user }} password: {{ .password }} - ain: "{{ .ain }}" # switch actor identification number without blanks (see AIN number on switch sticker) + ain: {{ .ain }} # switch actor identification number without blanks (see AIN number on switch sticker) diff --git a/util/templates/utils.go b/util/templates/utils.go index 01929383b..67119d315 100644 --- a/util/templates/utils.go +++ b/util/templates/utils.go @@ -12,6 +12,7 @@ func quote(value string) string { return fmt.Sprintf("'%s'", quoted) } +// yamlQuote quotes strings for yaml if they would otherwise by modified by the unmarshaler func yamlQuote(value string) string { input := fmt.Sprintf("key: %s", value) diff --git a/util/templates/utils_test.go b/util/templates/utils_test.go index c46689dcf..1a543aba8 100644 --- a/util/templates/utils_test.go +++ b/util/templates/utils_test.go @@ -4,11 +4,12 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" ) func TestYamlDecode(t *testing.T) { - for _, value := range []string{`value`, `!value`, `@value`, `"value"`, `"va"lue"`, `va'lue`, `@va'lue`, `0815`, `4711`, `#pwd`, ``} { + for _, value := range []string{`value`, `!value`, `@value`, `"value"`, `"va"lue"`, `va'lue`, `@va'lue`, `0815`, `"0815"`, `4711`, `#pwd`, ``} { t.Run(value, func(t *testing.T) { quoted := yamlQuote(value) input := fmt.Sprintf("key: %s", quoted) @@ -17,13 +18,9 @@ func TestYamlDecode(t *testing.T) { Value string `yaml:"key"` } - if err := yaml.Unmarshal([]byte(input), &res); err != nil { - t.Fatalf("expected %s (quoted: %s), got error %v", value, quoted, err) - } - - if value != res.Value { - t.Fatalf("expected %s (quoted: %s), got %s", value, quoted, res.Value) - } + err := yaml.Unmarshal([]byte(input), &res) + assert.NoError(t, err) + assert.Equal(t, value, res.Value) }) } }