Fix intermittent render test failure when the hostname has characters 3 & 4 repeated elsewhere

This commit is contained in:
Ben Banfield-Zanin committed 2026-11-18 11:05:51 +00:00
1 parent 8dbadda59a
commit cf791b82bc
3 files changed
+14 -6

No files matched your search

@@ -64,6 +64,7 @@ func readfile(path string) (string, error) {
return string(content), nil
}
// XXX I'm unclear if this filter is actually still used
func replace(old, new, src string) string {
return strings.ReplaceAll(src, old, new)
}
@@ -11,6 +11,7 @@ import (
"io"
"os"
"reflect"
"strings"
"testing"
)
@@ -32,19 +33,24 @@ func TestRenderConfig(t *testing.T) {
bytes.NewBuffer([]byte(`key: ${TEST_ENV}
quotedValue: ${SPECIAL_CHARS}
secretKey: ${SECRET_KEY}
hostname: ${THIS_HOSTNAME}`)),
replacedHostname: ${REPLACED_HOSTNAME}
rawHostname: ${THIS_HOSTNAME}`)),
},
env: map[string]string{
"TEST_ENV": "value",
"SPECIAL_CHARS": "{{ \"!ayamltype\" | quote }}",
"SECRET_KEY": "{{ readfile \"testdata/secret_key\" }}",
"THIS_HOSTNAME": fmt.Sprintf("{{ hostname | replace \"%s\" \"\" }}", droppedFromHostname),
"TEST_ENV": "value",
"SPECIAL_CHARS": "{{ \"!ayamltype\" | quote }}",
"SECRET_KEY": "{{ readfile \"testdata/secret_key\" }}",
"REPLACED_HOSTNAME": fmt.Sprintf("{{ hostname | replace \"%s\" \"\" }}", droppedFromHostname),
"THIS_HOSTNAME": "{{ hostname }}",
},
expected: map[string]any{
"key": "value",
"secretKey": "secret_value",
"quotedValue": "!ayamltype",
"hostname": hostname[0:2] + hostname[4:],
// the replace filter is strings.ReplaceAll under the hood.
// Unless we hard-code the hostname we don't know whether just 2 chars will be dropped or more (as there's multiple matches)
"replacedHostname": strings.ReplaceAll(hostname, droppedFromHostname, ""),
"rawHostname": hostname,
},
err: false,
},
+1
View File
@@ -0,0 +1 @@
CI: fix `matrix-tools` rendering test intermittently failing.