Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f93135a

Browse files
committed
chore(coderd/notifications): fix golden file test
1 parent dadad9f commit f93135a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

coderd/notifications/notifications_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,13 +1142,15 @@ func TestNotificationTemplates_Golden(t *testing.T) {
11421142

11431143
// Spin up the mock webhook server
11441144
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1145+
w.WriteHeader(http.StatusOK)
1146+
11451147
body, err := io.ReadAll(r.Body)
11461148
require.NoError(t, err)
11471149
var prettyJSON bytes.Buffer
11481150
err = json.Indent(&prettyJSON, body, "", " ")
11491151
require.NoError(t, err)
11501152

1151-
content := constantifyGoldenWebhook(prettyJSON.Bytes())
1153+
content := normalizeGoldenWebhook(prettyJSON.Bytes())
11521154

11531155
partialName := strings.Split(t.Name(), "/")[1]
11541156
goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden")
@@ -1157,15 +1159,13 @@ func TestNotificationTemplates_Golden(t *testing.T) {
11571159
require.NoError(t, err, "want no error creating golden file directory")
11581160
err = os.WriteFile(goldenFile, content, 0o600)
11591161
require.NoError(t, err, "want no error writing body golden file")
1160-
w.WriteHeader(http.StatusOK)
11611162
return
11621163
}
11631164

11641165
wantBody, err := os.ReadFile(goldenFile)
11651166
require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint))
1166-
require.Equal(t, string(wantBody), prettyJSON, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint))
1167+
require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint))
11671168

1168-
w.WriteHeader(http.StatusOK)
11691169
}))
11701170
t.Cleanup(server.Close)
11711171

@@ -1235,7 +1235,7 @@ func normalizeGoldenEmail(content []byte) []byte {
12351235
return content
12361236
}
12371237

1238-
func constantifyGoldenWebhook(content []byte) []byte {
1238+
func normalizeGoldenWebhook(content []byte) []byte {
12391239
const constantUUID = "00000000-0000-0000-0000-000000000000"
12401240
uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`)
12411241
content = uuidRegex.ReplaceAll(content, []byte(constantUUID))

coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
}
1717
],
1818
"labels": {
19-
"account_activator_user_name": "rob",
2019
"activated_account_name": "bobby",
21-
"activated_account_user_name": "william tables"
20+
"activated_account_user_name": "William Tables",
21+
"initiator": "rob"
2222
},
2323
"data": null
2424
},
2525
"title": "User account \"bobby\" activated",
2626
"title_markdown": "User account \"bobby\" activated",
27-
"body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to william tables and was activated by rob.",
28-
"body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**."
27+
"body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to William Tables and was activated by rob.",
28+
"body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **William Tables** and was activated by **rob**."
2929
}

coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717
],
1818
"labels": {
19-
"account_creator": "rob",
2019
"created_account_name": "bobby",
21-
"created_account_user_name": "William Tables"
20+
"created_account_user_name": "William Tables",
21+
"initiator": "rob"
2222
},
2323
"data": null
2424
},

0 commit comments

Comments
 (0)