Skip to content

Commit ef13dde

Browse files
committed
normalize line endings
1 parent be09414 commit ef13dde

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

coderd/notifications/notifications_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
13291329

13301330
wantBody, err := os.ReadFile(goldenFile)
13311331
require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint))
1332+
wantBody = normalizeLineEndings(wantBody)
13321333
require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint))
13331334
})
13341335
})
@@ -1339,7 +1340,11 @@ func TestNotificationTemplates_Golden(t *testing.T) {
13391340
// Required for Windows compatibility.
13401341
func normalizeLineEndings(content []byte) []byte {
13411342
content = bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n"))
1342-
return bytes.ReplaceAll(content, []byte("\r"), []byte("\n"))
1343+
content = bytes.ReplaceAll(content, []byte("\r"), []byte("\n"))
1344+
// some tests generate escaped line endings, so we have to replace them too
1345+
content = bytes.ReplaceAll(content, []byte("\\r\\n"), []byte("\\n"))
1346+
content = bytes.ReplaceAll(content, []byte("\\r"), []byte("\\n"))
1347+
return content
13431348
}
13441349

13451350
func normalizeGoldenEmail(content []byte) []byte {
@@ -1362,7 +1367,6 @@ func normalizeGoldenEmail(content []byte) []byte {
13621367
content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate))
13631368
content = messageIDRegex.ReplaceAll(content, []byte("Message-Id: "+constantMessageID))
13641369
content = bytes.ReplaceAll(content, boundary, []byte(constantBoundary))
1365-
content = normalizeLineEndings(content)
13661370

13671371
return content
13681372
}

0 commit comments

Comments
 (0)