diff --git a/matrix-tools/internal/pkg/renderer/renderer.go b/matrix-tools/internal/pkg/renderer/renderer.go index 1a0035ea..263f5a71 100644 --- a/matrix-tools/internal/pkg/renderer/renderer.go +++ b/matrix-tools/internal/pkg/renderer/renderer.go @@ -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) } diff --git a/matrix-tools/internal/pkg/renderer/renderer_test.go b/matrix-tools/internal/pkg/renderer/renderer_test.go index be52823c..3fd2d755 100644 --- a/matrix-tools/internal/pkg/renderer/renderer_test.go +++ b/matrix-tools/internal/pkg/renderer/renderer_test.go @@ -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, }, diff --git a/newsfragments/1825.internal.md b/newsfragments/1825.internal.md new file mode 100644 index 00000000..3d22d0f1 --- /dev/null +++ b/newsfragments/1825.internal.md @@ -0,0 +1 @@ +CI: fix `matrix-tools` rendering test intermittently failing.