From b2523b1c0993b53c42cb978ab48b0108abc5ae01 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 3 Sep 2024 12:37:51 +0200 Subject: [PATCH 01/24] WIP --- coderd/notifications/events.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coderd/notifications/events.go b/coderd/notifications/events.go index 6ba88c239edc8..ebc314caab08d 100644 --- a/coderd/notifications/events.go +++ b/coderd/notifications/events.go @@ -28,5 +28,6 @@ var ( // Template-related events. var ( - TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be") + TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be") + TemplateWorkspaceBuildSummary = uuid.MustParse("bc0d9b9c-6dca-40a7-a209-fb2681e3341a") ) From 9559138ca21c510b93a476796a32b83a68b18171 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 3 Sep 2024 12:46:50 +0200 Subject: [PATCH 02/24] WIP2 --- coderd/database/migrations/000249_email_reports.down.sql | 0 coderd/database/migrations/000249_email_reports.up.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 coderd/database/migrations/000249_email_reports.down.sql create mode 100644 coderd/database/migrations/000249_email_reports.up.sql diff --git a/coderd/database/migrations/000249_email_reports.down.sql b/coderd/database/migrations/000249_email_reports.down.sql new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql new file mode 100644 index 0000000000000..e69de29bb2d1d From 39d80eb7f3e3420758a5aedf3d857f7f3b320c45 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 3 Sep 2024 14:55:28 +0200 Subject: [PATCH 03/24] Template body --- .../migrations/000249_email_reports.down.sql | 1 + .../migrations/000249_email_reports.up.sql | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/coderd/database/migrations/000249_email_reports.down.sql b/coderd/database/migrations/000249_email_reports.down.sql index e69de29bb2d1d..5d295953ed778 100644 --- a/coderd/database/migrations/000249_email_reports.down.sql +++ b/coderd/database/migrations/000249_email_reports.down.sql @@ -0,0 +1 @@ +DELETE FROM notification_templates WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index e69de29bb2d1d..9130dab5369af 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -0,0 +1,22 @@ +INSERT INTO notification_templates (id, name, title_template, body_template, "group", actions) +VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"', + E'Hi {{.UserName}}, + +Template {{.Labels.template_display_name}} has failed to build {{.Labels.failed_builds})/{{.Labels.total_builds}} times over the last {{.Labels.report_frequency}} and may be unstable. + +**Report:** + +{{range $index, $version := .Labels.template_versions}} + {{add $index 1}}. "{{$version.TemplateDisplayName}}" failed {{$version.FailedCount}} time{{if gt $version.FailedCount 1}}s{{end}}: + {{range $i, $build := $version.FailedBuilds}} + * [{{$build.WorkspaceOwnerUsername}} / {{$build.WorkspaceName}} / #{{$build.BuildNumber}}]({{base_url}}/@{{$build.WorkspaceOwnerUsername}}/{{$build.WorkspaceName}}/builds/{{$build.BuildNumber}}) + {{end}} +{{end}} + +We recommend reviewing these issues to ensure future builds are successful.', + 'Template Events', '[ + { + "label": "View workspaces", + "url": "{{ base_url }}/workspaces?filter=template%3A{{.Labels.template_name}}" + } + ]'::jsonb); From d9fef242c8c8c11f4f8a923ddac490868a2d705f Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 3 Sep 2024 15:04:01 +0200 Subject: [PATCH 04/24] fmt --- coderd/notifications/events.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coderd/notifications/events.go b/coderd/notifications/events.go index ebc314caab08d..f043d86065023 100644 --- a/coderd/notifications/events.go +++ b/coderd/notifications/events.go @@ -28,6 +28,7 @@ var ( // Template-related events. var ( - TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be") + TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be") + TemplateWorkspaceBuildSummary = uuid.MustParse("bc0d9b9c-6dca-40a7-a209-fb2681e3341a") ) From 994f48402818942d289a929bf14b39a2cc81f88e Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:36:11 +0200 Subject: [PATCH 05/24] adjust payload --- .../migrations/000249_email_reports.up.sql | 10 ++-- coderd/notifications/notifications_test.go | 50 +++++++++++++++++++ coderd/notifications/types/payload.go | 1 + 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index 9130dab5369af..2c8a5c8619d4c 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -2,14 +2,14 @@ INSERT INTO notification_templates (id, name, title_template, body_template, "gr VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"', E'Hi {{.UserName}}, -Template {{.Labels.template_display_name}} has failed to build {{.Labels.failed_builds})/{{.Labels.total_builds}} times over the last {{.Labels.report_frequency}} and may be unstable. +Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_builds})/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. **Report:** -{{range $index, $version := .Labels.template_versions}} - {{add $index 1}}. "{{$version.TemplateDisplayName}}" failed {{$version.FailedCount}} time{{if gt $version.FailedCount 1}}s{{end}}: - {{range $i, $build := $version.FailedBuilds}} - * [{{$build.WorkspaceOwnerUsername}} / {{$build.WorkspaceName}} / #{{$build.BuildNumber}}]({{base_url}}/@{{$build.WorkspaceOwnerUsername}}/{{$build.WorkspaceName}}/builds/{{$build.BuildNumber}}) +{{range $index, $version := .Data.template_versions}} + {{add $index 1}}. "{{$version.template_version_name}}" failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: + {{range $i, $build := $version.failed_builds}} + * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) {{end}} {{end}} diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 3e9a68f7207c6..d3f1f8ca67634 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -837,6 +837,56 @@ func TestNotificationTemplatesCanRender(t *testing.T) { }, }, }, + { + name: "TemplateWorkspaceBuildSummary", + id: notifications.TemplateWorkspaceBuildSummary, + payload: types.MessagePayload{ + UserName: "bobby", + Labels: map[string]string{ + "template_name": "bobby-first-template", + "template_display_name": "Bobby First Template", + }, + Data: map[string]any{ + "failed_builds": 4, + "total_builds": 55, + "report_frequency": "week", + "template_versions": []map[string]any{ + { + "template_version_name": "bobby-template-version-1", + "failed_count": 3, + "builds": []map[string]any{ + { + "workspace_owner_username": "mtojek", + "workspace_name": "workspace-1", + "build_number": 1234, + }, + { + "workspace_owner_username": "johndoe", + "workspace_name": "my-workspace-3", + "build_number": 5678, + }, + { + "workspace_owner_username": "jack", + "workspace_name": "workwork", + "build_number": 774, + }, + }, + }, + { + "template_version_name": "bobby-template-version-2", + "failed_count": 1, + "builds": []map[string]any{ + { + "workspace_owner_username": "ben", + "workspace_name": "cool-workspace", + "build_number": 8888, + }, + }, + }, + }, + }, + }, + }, } allTemplates, err := enumerateAllTemplates(t) diff --git a/coderd/notifications/types/payload.go b/coderd/notifications/types/payload.go index ba666219af654..5ef67be6ada6f 100644 --- a/coderd/notifications/types/payload.go +++ b/coderd/notifications/types/payload.go @@ -16,4 +16,5 @@ type MessagePayload struct { Actions []TemplateAction `json:"actions"` Labels map[string]string `json:"labels"` + Data map[string]any `json:"data,omitempty"` } From c55a6889857c9913d9adf1b4fbce49d9aaa9c2ed Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:42:19 +0200 Subject: [PATCH 06/24] fix --- coderd/database/migrations/000249_email_reports.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index 2c8a5c8619d4c..62c3e0a661774 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -2,7 +2,7 @@ INSERT INTO notification_templates (id, name, title_template, body_template, "gr VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"', E'Hi {{.UserName}}, -Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_builds})/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. +Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_builds}}/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. **Report:** From 796da33cc248e940a264303e812d98cbcb7fcda1 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:57:31 +0200 Subject: [PATCH 07/24] no index --- coderd/database/migrations/000249_email_reports.up.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index 62c3e0a661774..e15081afd02e0 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -6,8 +6,8 @@ Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_bu **Report:** -{{range $index, $version := .Data.template_versions}} - {{add $index 1}}. "{{$version.template_version_name}}" failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: +{{range _, $version := .Data.template_versions}} + **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: {{range $i, $build := $version.failed_builds}} * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) {{end}} From c23da288e9dbe0083aca8ecf351ca1734ea6a874 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 13:16:10 +0200 Subject: [PATCH 08/24] fix range --- coderd/database/migrations/000249_email_reports.up.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index e15081afd02e0..6d196c6737db2 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -6,9 +6,9 @@ Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_bu **Report:** -{{range _, $version := .Data.template_versions}} +{{range $version := .Data.template_versions}} **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: - {{range $i, $build := $version.failed_builds}} + {{range $build := $version.failed_builds}} * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) {{end}} {{end}} From 53dc29fe4c66d06dbe129e655d5c19e590a4bad8 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 13:25:17 +0200 Subject: [PATCH 09/24] fix: base_url --- coderd/notifications/notifications_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index d3f1f8ca67634..0b556a43b635c 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -919,12 +919,12 @@ func TestNotificationTemplatesCanRender(t *testing.T) { Scan(&titleTmpl, &bodyTmpl) require.NoError(t, err, "failed to query body template for template:", tc.id) - title, err := render.GoTemplate(titleTmpl, tc.payload, nil) + title, err := render.GoTemplate(titleTmpl, tc.payload, defaultHelpers()) require.NotContainsf(t, title, render.NoValue, "template %q is missing a label value", tc.name) require.NoError(t, err, "failed to render notification title template") require.NotEmpty(t, title, "title should not be empty") - body, err := render.GoTemplate(bodyTmpl, tc.payload, nil) + body, err := render.GoTemplate(bodyTmpl, tc.payload, defaultHelpers()) require.NoError(t, err, "failed to render notification body template") require.NotEmpty(t, body, "body should not be empty") }) From 1753beb3bfc93c7fad5d03c619d39a3ba676f241 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 14:05:35 +0200 Subject: [PATCH 10/24] test --- coderd/notifications/notifications_test.go | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 0b556a43b635c..ec94ea5e6e38d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -5,6 +5,7 @@ import ( "context" _ "embed" "encoding/json" + "flag" "fmt" "go/ast" "go/parser" @@ -12,8 +13,11 @@ import ( "net/http" "net/http/httptest" "net/url" + "os" + "path/filepath" "slices" "sort" + "strings" "sync" "sync/atomic" "testing" @@ -46,6 +50,9 @@ import ( "github.com/coder/coder/v2/testutil" ) +// updateGoldenFiles is a flag that can be set to update golden files. +var updateGoldenFiles = flag.Bool("update", false, "Update golden files") + func TestMain(m *testing.M) { goleak.VerifyTestMain(m) } @@ -927,6 +934,24 @@ func TestNotificationTemplatesCanRender(t *testing.T) { body, err := render.GoTemplate(bodyTmpl, tc.payload, defaultHelpers()) require.NoError(t, err, "failed to render notification body template") require.NotEmpty(t, body, "body should not be empty") + + partialName := strings.Join(strings.Split(t.Name(), "/")[1:], "_") + goldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-body.md.golden") + + if *updateGoldenFiles { + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + f, err := os.Create(goldenFile) + require.NoError(t, err, "want no error creating golden file") + defer f.Close() + _, err = f.WriteString(body) + require.NoError(t, err, "want no error writing golden file") + return + } + + want, err := os.ReadFile(goldenFile) + require.NoError(t, err, "open golden file, run \"make update-golden-files\" and commit the changes") + require.Equal(t, string(want), body, "body should be equal") }) } } From e200056453816bc2328009ee4c70cb9fa09f4db8 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:12:25 +0000 Subject: [PATCH 11/24] WIP --- coderd/notifications/notifications_test.go | 2 +- .../TemplateTemplateDeleted-body.md.golden | 3 +++ .../TemplateUserAccountActivated-body.md.golden | 2 ++ .../TemplateUserAccountCreated-body.md.golden | 3 +++ .../TemplateUserAccountDeleted-body.md.golden | 3 +++ .../TemplateUserAccountSuspended-body.md.golden | 2 ++ .../TemplateWorkspaceAutoUpdated-body.md.golden | 3 +++ ...emplateWorkspaceAutobuildFailed-body.md.golden | 3 +++ .../TemplateWorkspaceBuildSummary-body.md.golden | 15 +++++++++++++++ .../TemplateWorkspaceDeleted-body.md.golden | 4 ++++ .../TemplateWorkspaceDormant-body.md.golden | 5 +++++ ...plateWorkspaceManualBuildFailed-body.md.golden | 4 ++++ ...plateWorkspaceMarkedForDeletion-body.md.golden | 4 ++++ .../TemplateYourAccountActivated-body.md.golden | 2 ++ .../TemplateYourAccountSuspended-body.md.golden | 2 ++ 15 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index ec94ea5e6e38d..4131894ce5802 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -51,7 +51,7 @@ import ( ) // updateGoldenFiles is a flag that can be set to update golden files. -var updateGoldenFiles = flag.Bool("update", false, "Update golden files") +var updateGoldenFiles = flag.Bool("update", true, "Update golden files") func TestMain(m *testing.M) { goleak.VerifyTestMain(m) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden new file mode 100644 index 0000000000000..e22ff54d6946f --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -0,0 +1,3 @@ +Hi bobby + +The template **bobby-template** was deleted by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden new file mode 100644 index 0000000000000..3152b48653bc4 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden @@ -0,0 +1,2 @@ +Hi bobby, +User account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden new file mode 100644 index 0000000000000..8ca6f71e2287e --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden @@ -0,0 +1,3 @@ +Hi bobby, + +New user account **bobby** has been created. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden new file mode 100644 index 0000000000000..a65cacb29bc43 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden @@ -0,0 +1,3 @@ +Hi bobby, + +User account **bobby** has been deleted. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden new file mode 100644 index 0000000000000..1edf1fcdb9c22 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden @@ -0,0 +1,2 @@ +Hi bobby, +User account **bobby** has been suspended. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden new file mode 100644 index 0000000000000..e9deb040a0682 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -0,0 +1,3 @@ +Hi bobby +Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). +Reason for update: **template now includes catnip** \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden new file mode 100644 index 0000000000000..255d0e3072f53 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden @@ -0,0 +1,3 @@ +Hi bobby +Automatic build of your workspace **bobby-workspace** failed. +The specified reason was "**autostart**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden new file mode 100644 index 0000000000000..e90373b784786 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden @@ -0,0 +1,15 @@ +Hi bobby, + +Template Bobby First Template has failed to build 4/55 times over the last week and may be unstable. + +**Report:** + + + **bobby-template-version-1** failed 3 times: + + + **bobby-template-version-2** failed 1 time: + + + +We recommend reviewing these issues to ensure future builds are successful. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden new file mode 100644 index 0000000000000..a95017cd665c2 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden @@ -0,0 +1,4 @@ +Hi bobby + +Your workspace **bobby-workspace** was deleted. +The specified reason was "**autodeleted due to dormancy (autobuild)**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden new file mode 100644 index 0000000000000..be1d24675faf3 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden @@ -0,0 +1,5 @@ +Hi bobby + +Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. +Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. +To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden new file mode 100644 index 0000000000000..e8d6f2be031e2 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden @@ -0,0 +1,4 @@ +Hi bobby, + +A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). +The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden new file mode 100644 index 0000000000000..03870559b1dcc --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden @@ -0,0 +1,4 @@ +Hi bobby + +Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. +To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden new file mode 100644 index 0000000000000..811d766a91220 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden @@ -0,0 +1,2 @@ +Hi bobby, +Your account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden new file mode 100644 index 0000000000000..65665ae747e99 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden @@ -0,0 +1,2 @@ +Hi bobby, +Your account **bobby** has been suspended. \ No newline at end of file From 1118d67f8199c0e6e9bdf63918ab1b02bb879bdb Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:18:01 +0000 Subject: [PATCH 12/24] WIP --- coderd/database/migrations/000249_email_reports.up.sql | 2 +- coderd/notifications/notifications_test.go | 6 +++--- .../TemplateWorkspaceBuildSummary-body.md.golden | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index 6d196c6737db2..a5ec57f2f8bcc 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -10,7 +10,7 @@ Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_bu **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: {{range $build := $version.failed_builds}} * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) - {{end}} + {{- end}} {{end}} We recommend reviewing these issues to ensure future builds are successful.', diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 4131894ce5802..28eab2ee7e987 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -51,7 +51,7 @@ import ( ) // updateGoldenFiles is a flag that can be set to update golden files. -var updateGoldenFiles = flag.Bool("update", true, "Update golden files") +var updateGoldenFiles = flag.Bool("update", false, "Update golden files") func TestMain(m *testing.M) { goleak.VerifyTestMain(m) @@ -861,7 +861,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { { "template_version_name": "bobby-template-version-1", "failed_count": 3, - "builds": []map[string]any{ + "failed_builds": []map[string]any{ { "workspace_owner_username": "mtojek", "workspace_name": "workspace-1", @@ -882,7 +882,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { { "template_version_name": "bobby-template-version-2", "failed_count": 1, - "builds": []map[string]any{ + "failed_builds": []map[string]any{ { "workspace_owner_username": "ben", "workspace_name": "cool-workspace", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden index e90373b784786..c506ce9e75bfd 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden @@ -7,9 +7,13 @@ Template Bobby First Template has failed to build 4/55 times over the last week **bobby-template-version-1** failed 3 times: + * [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234) + * [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678) + * [jack / workwork / #774](http://test.com/@jack/workwork/builds/774) **bobby-template-version-2** failed 1 time: + * [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888) We recommend reviewing these issues to ensure future builds are successful. \ No newline at end of file From 7c7e0f95a95ff6797565ad45d9e7e1dfc27de6fa Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:24:55 +0000 Subject: [PATCH 13/24] WIP --- coderd/database/migrations/000249_email_reports.up.sql | 4 +--- coderd/notifications/notifications_test.go | 2 +- .../TemplateWorkspaceBuildSummary-body.md.golden | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql index a5ec57f2f8bcc..07f319f1ba38c 100644 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ b/coderd/database/migrations/000249_email_reports.up.sql @@ -2,17 +2,15 @@ INSERT INTO notification_templates (id, name, title_template, body_template, "gr VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"', E'Hi {{.UserName}}, -Template {{.Labels.template_display_name}} has failed to build {{.Data.failed_builds}}/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. +Template **{{.Labels.template_display_name}}** has failed to build {{.Data.failed_builds}}/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. **Report:** - {{range $version := .Data.template_versions}} **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: {{range $build := $version.failed_builds}} * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) {{- end}} {{end}} - We recommend reviewing these issues to ensure future builds are successful.', 'Template Events', '[ { diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 28eab2ee7e987..f95a877d6659d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -51,7 +51,7 @@ import ( ) // updateGoldenFiles is a flag that can be set to update golden files. -var updateGoldenFiles = flag.Bool("update", false, "Update golden files") +var updateGoldenFiles = flag.Bool("update", true, "Update golden files") func TestMain(m *testing.M) { goleak.VerifyTestMain(m) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden index c506ce9e75bfd..966005f6a1feb 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden @@ -1,10 +1,9 @@ Hi bobby, -Template Bobby First Template has failed to build 4/55 times over the last week and may be unstable. +Template **Bobby First Template** has failed to build 4/55 times over the last week and may be unstable. **Report:** - **bobby-template-version-1** failed 3 times: * [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234) @@ -15,5 +14,4 @@ Template Bobby First Template has failed to build 4/55 times over the last week * [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888) - We recommend reviewing these issues to ensure future builds are successful. \ No newline at end of file From ca0d9ee77fe1e9ae6bfd3e2e15359f59fceca3e4 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 14:25:46 +0200 Subject: [PATCH 14/24] s/bobby/Bobby/g --- coderd/database/models.go | 2 +- coderd/database/querier.go | 2 +- coderd/database/queries.sql.go | 2 +- coderd/notifications/notifications_test.go | 28 +++++++++++----------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/coderd/database/models.go b/coderd/database/models.go index 959609d82eb79..18571981a4c92 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.26.0 package database diff --git a/coderd/database/querier.go b/coderd/database/querier.go index c614a03834a9b..45d154ae239b7 100644 --- a/coderd/database/querier.go +++ b/coderd/database/querier.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.26.0 package database diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index fc388e55247d0..0574da2dd00d1 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.25.0 +// sqlc v1.26.0 package database diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index f95a877d6659d..21b931237a08d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -700,7 +700,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceDeleted", id: notifications.TemplateWorkspaceDeleted, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "autodeleted due to dormancy", @@ -712,7 +712,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceAutobuildFailed", id: notifications.TemplateWorkspaceAutobuildFailed, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "autostart", @@ -723,7 +723,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceDormant", id: notifications.TemplateWorkspaceDormant, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "breached the template's threshold for inactivity", @@ -737,7 +737,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceAutoUpdated", id: notifications.TemplateWorkspaceAutoUpdated, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "template_version_name": "1.0", @@ -749,7 +749,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceMarkedForDeletion", id: notifications.TemplateWorkspaceMarkedForDeletion, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "template updated to new dormancy policy", @@ -762,7 +762,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateUserAccountCreated", id: notifications.TemplateUserAccountCreated, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "created_account_name": "bobby", }, @@ -772,7 +772,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateUserAccountDeleted", id: notifications.TemplateUserAccountDeleted, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "deleted_account_name": "bobby", }, @@ -782,7 +782,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateUserAccountSuspended", id: notifications.TemplateUserAccountSuspended, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "suspended_account_name": "bobby", }, @@ -792,7 +792,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateUserAccountActivated", id: notifications.TemplateUserAccountActivated, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "activated_account_name": "bobby", }, @@ -802,7 +802,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateYourAccountSuspended", id: notifications.TemplateYourAccountSuspended, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "suspended_account_name": "bobby", }, @@ -812,7 +812,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateYourAccountActivated", id: notifications.TemplateYourAccountActivated, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "activated_account_name": "bobby", }, @@ -822,7 +822,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateTemplateDeleted", id: notifications.TemplateTemplateDeleted, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-template", "initiator": "rob", @@ -833,7 +833,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceManualBuildFailed", id: notifications.TemplateWorkspaceManualBuildFailed, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "name": "bobby-workspace", "template_name": "bobby-template", @@ -848,7 +848,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { name: "TemplateWorkspaceBuildSummary", id: notifications.TemplateWorkspaceBuildSummary, payload: types.MessagePayload{ - UserName: "bobby", + UserName: "Bobby", Labels: map[string]string{ "template_name": "bobby-first-template", "template_display_name": "Bobby First Template", From d91742cabdfd20af7b344c7b487f595c025f7b51 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:26:29 +0000 Subject: [PATCH 15/24] gen --- .../rendered-templates/TemplateTemplateDeleted-body.md.golden | 2 +- .../TemplateUserAccountActivated-body.md.golden | 2 +- .../TemplateUserAccountCreated-body.md.golden | 2 +- .../TemplateUserAccountDeleted-body.md.golden | 2 +- .../TemplateUserAccountSuspended-body.md.golden | 2 +- .../TemplateWorkspaceAutoUpdated-body.md.golden | 2 +- .../TemplateWorkspaceAutobuildFailed-body.md.golden | 2 +- .../TemplateWorkspaceBuildSummary-body.md.golden | 2 +- .../rendered-templates/TemplateWorkspaceDeleted-body.md.golden | 2 +- .../rendered-templates/TemplateWorkspaceDormant-body.md.golden | 2 +- .../TemplateWorkspaceManualBuildFailed-body.md.golden | 2 +- .../TemplateWorkspaceMarkedForDeletion-body.md.golden | 2 +- .../TemplateYourAccountActivated-body.md.golden | 2 +- .../TemplateYourAccountSuspended-body.md.golden | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden index e22ff54d6946f..be3a61e695652 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -1,3 +1,3 @@ -Hi bobby +Hi Bobby The template **bobby-template** was deleted by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden index 3152b48653bc4..2665a781492ea 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden @@ -1,2 +1,2 @@ -Hi bobby, +Hi Bobby, User account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden index 8ca6f71e2287e..e5a5be89c11e0 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden @@ -1,3 +1,3 @@ -Hi bobby, +Hi Bobby, New user account **bobby** has been created. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden index a65cacb29bc43..bd1066c25fb50 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden @@ -1,3 +1,3 @@ -Hi bobby, +Hi Bobby, User account **bobby** has been deleted. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden index 1edf1fcdb9c22..70a43f2960ec0 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden @@ -1,2 +1,2 @@ -Hi bobby, +Hi Bobby, User account **bobby** has been suspended. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden index e9deb040a0682..79248150987c2 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -1,3 +1,3 @@ -Hi bobby +Hi Bobby Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). Reason for update: **template now includes catnip** \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden index 255d0e3072f53..731f71f22ae88 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden @@ -1,3 +1,3 @@ -Hi bobby +Hi Bobby Automatic build of your workspace **bobby-workspace** failed. The specified reason was "**autostart**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden index 966005f6a1feb..d5b21eb06d042 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden @@ -1,4 +1,4 @@ -Hi bobby, +Hi Bobby, Template **Bobby First Template** has failed to build 4/55 times over the last week and may be unstable. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden index a95017cd665c2..06aec5692465f 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden @@ -1,4 +1,4 @@ -Hi bobby +Hi Bobby Your workspace **bobby-workspace** was deleted. The specified reason was "**autodeleted due to dormancy (autobuild)**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden index be1d24675faf3..aa10f4864cf24 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden @@ -1,4 +1,4 @@ -Hi bobby +Hi Bobby Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden index e8d6f2be031e2..45f8733dd2931 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden @@ -1,4 +1,4 @@ -Hi bobby, +Hi Bobby, A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden index 03870559b1dcc..3d9fe99accd94 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden @@ -1,4 +1,4 @@ -Hi bobby +Hi Bobby Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden index 811d766a91220..160fdc66e8990 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden @@ -1,2 +1,2 @@ -Hi bobby, +Hi Bobby, Your account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden index 65665ae747e99..ce30139213bb0 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden @@ -1,2 +1,2 @@ -Hi bobby, +Hi Bobby, Your account **bobby** has been suspended. \ No newline at end of file From 9fe5defbe0e34fa641489c9baacfed7b0183a9f1 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 12:26:52 +0000 Subject: [PATCH 16/24] back to false --- coderd/notifications/notifications_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 21b931237a08d..d70a22e933ead 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -51,7 +51,7 @@ import ( ) // updateGoldenFiles is a flag that can be set to update golden files. -var updateGoldenFiles = flag.Bool("update", true, "Update golden files") +var updateGoldenFiles = flag.Bool("update", false, "Update golden files") func TestMain(m *testing.M) { goleak.VerifyTestMain(m) From 4d95288b085e183f44b16633db603eeb6bffe42c Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 14:28:11 +0200 Subject: [PATCH 17/24] fix --- coderd/database/models.go | 2 +- coderd/database/querier.go | 2 +- coderd/database/queries.sql.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coderd/database/models.go b/coderd/database/models.go index 18571981a4c92..959609d82eb79 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.25.0 package database diff --git a/coderd/database/querier.go b/coderd/database/querier.go index 45d154ae239b7..c614a03834a9b 100644 --- a/coderd/database/querier.go +++ b/coderd/database/querier.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.25.0 package database diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 0574da2dd00d1..fc388e55247d0 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.25.0 package database From b12dcfcc2f6273ebce6543f6eee5aeff7b9b8f39 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 17:31:22 +0200 Subject: [PATCH 18/24] Address PR feedback --- .../migrations/000249_email_reports.down.sql | 1 - .../migrations/000249_email_reports.up.sql | 20 -------- coderd/notifications/notifications_test.go | 50 ------------------- ...mplateWorkspaceBuildSummary-body.md.golden | 17 ------- coderd/notifications/types/payload.go | 1 - 5 files changed, 89 deletions(-) delete mode 100644 coderd/database/migrations/000249_email_reports.down.sql delete mode 100644 coderd/database/migrations/000249_email_reports.up.sql delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden diff --git a/coderd/database/migrations/000249_email_reports.down.sql b/coderd/database/migrations/000249_email_reports.down.sql deleted file mode 100644 index 5d295953ed778..0000000000000 --- a/coderd/database/migrations/000249_email_reports.down.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM notification_templates WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; diff --git a/coderd/database/migrations/000249_email_reports.up.sql b/coderd/database/migrations/000249_email_reports.up.sql deleted file mode 100644 index 07f319f1ba38c..0000000000000 --- a/coderd/database/migrations/000249_email_reports.up.sql +++ /dev/null @@ -1,20 +0,0 @@ -INSERT INTO notification_templates (id, name, title_template, body_template, "group", actions) -VALUES ('bc0d9b9c-6dca-40a7-a209-fb2681e3341a', 'Report: Workspace Builds Failed For Template', E'Workspace builds failed for template "{{.Labels.template_display_name}}"', - E'Hi {{.UserName}}, - -Template **{{.Labels.template_display_name}}** has failed to build {{.Data.failed_builds}}/{{.Data.total_builds}} times over the last {{.Data.report_frequency}} and may be unstable. - -**Report:** -{{range $version := .Data.template_versions}} - **{{$version.template_version_name}}** failed {{$version.failed_count}} time{{if gt $version.failed_count 1}}s{{end}}: - {{range $build := $version.failed_builds}} - * [{{$build.workspace_owner_username}} / {{$build.workspace_name}} / #{{$build.build_number}}]({{base_url}}/@{{$build.workspace_owner_username}}/{{$build.workspace_name}}/builds/{{$build.build_number}}) - {{- end}} -{{end}} -We recommend reviewing these issues to ensure future builds are successful.', - 'Template Events', '[ - { - "label": "View workspaces", - "url": "{{ base_url }}/workspaces?filter=template%3A{{.Labels.template_name}}" - } - ]'::jsonb); diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index d70a22e933ead..b57fba605aff1 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -844,56 +844,6 @@ func TestNotificationTemplatesCanRender(t *testing.T) { }, }, }, - { - name: "TemplateWorkspaceBuildSummary", - id: notifications.TemplateWorkspaceBuildSummary, - payload: types.MessagePayload{ - UserName: "Bobby", - Labels: map[string]string{ - "template_name": "bobby-first-template", - "template_display_name": "Bobby First Template", - }, - Data: map[string]any{ - "failed_builds": 4, - "total_builds": 55, - "report_frequency": "week", - "template_versions": []map[string]any{ - { - "template_version_name": "bobby-template-version-1", - "failed_count": 3, - "failed_builds": []map[string]any{ - { - "workspace_owner_username": "mtojek", - "workspace_name": "workspace-1", - "build_number": 1234, - }, - { - "workspace_owner_username": "johndoe", - "workspace_name": "my-workspace-3", - "build_number": 5678, - }, - { - "workspace_owner_username": "jack", - "workspace_name": "workwork", - "build_number": 774, - }, - }, - }, - { - "template_version_name": "bobby-template-version-2", - "failed_count": 1, - "failed_builds": []map[string]any{ - { - "workspace_owner_username": "ben", - "workspace_name": "cool-workspace", - "build_number": 8888, - }, - }, - }, - }, - }, - }, - }, } allTemplates, err := enumerateAllTemplates(t) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden deleted file mode 100644 index d5b21eb06d042..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildSummary-body.md.golden +++ /dev/null @@ -1,17 +0,0 @@ -Hi Bobby, - -Template **Bobby First Template** has failed to build 4/55 times over the last week and may be unstable. - -**Report:** - - **bobby-template-version-1** failed 3 times: - - * [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234) - * [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678) - * [jack / workwork / #774](http://test.com/@jack/workwork/builds/774) - - **bobby-template-version-2** failed 1 time: - - * [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888) - -We recommend reviewing these issues to ensure future builds are successful. \ No newline at end of file diff --git a/coderd/notifications/types/payload.go b/coderd/notifications/types/payload.go index 5ef67be6ada6f..ba666219af654 100644 --- a/coderd/notifications/types/payload.go +++ b/coderd/notifications/types/payload.go @@ -16,5 +16,4 @@ type MessagePayload struct { Actions []TemplateAction `json:"actions"` Labels map[string]string `json:"labels"` - Data map[string]any `json:"data,omitempty"` } From 412e9b27e900a954219ac22a794e8f556e469c68 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 17:32:38 +0200 Subject: [PATCH 19/24] db=ci --- coderd/notifications/notifications_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index b57fba605aff1..7c9917656e440 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -900,7 +900,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) { } want, err := os.ReadFile(goldenFile) - require.NoError(t, err, "open golden file, run \"make update-golden-files\" and commit the changes") + require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes") require.Equal(t, string(want), body, "body should be equal") }) } From 419c56aa7b70e27d066d91ad981090267b2dc3f9 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 17:37:40 +0200 Subject: [PATCH 20/24] golden --- coderd/notifications/notifications_test.go | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 7c9917656e440..d927ba3e2385a 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -17,7 +17,6 @@ import ( "path/filepath" "slices" "sort" - "strings" "sync" "sync/atomic" "testing" @@ -885,23 +884,26 @@ func TestNotificationTemplatesCanRender(t *testing.T) { require.NoError(t, err, "failed to render notification body template") require.NotEmpty(t, body, "body should not be empty") - partialName := strings.Join(strings.Split(t.Name(), "/")[1:], "_") - goldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-body.md.golden") + bodyGoldenFile := filepath.Join("testdata", "rendered-templates", t.Name()+"-body.md.golden") + titleGoldenFile := filepath.Join("testdata", "rendered-templates", t.Name()+"-title.md.golden") if *updateGoldenFiles { - err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + err = os.MkdirAll(filepath.Dir(bodyGoldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - f, err := os.Create(goldenFile) - require.NoError(t, err, "want no error creating golden file") - defer f.Close() - _, err = f.WriteString(body) - require.NoError(t, err, "want no error writing golden file") + err = os.WriteFile(bodyGoldenFile, []byte(body), 0600) + require.NoError(t, err, "want no error writing body golden file") + err = os.WriteFile(titleGoldenFile, []byte(title), 0600) + require.NoError(t, err, "want no error writing title golden file") return } - want, err := os.ReadFile(goldenFile) + wantBody, err := os.ReadFile(bodyGoldenFile) require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes") - require.Equal(t, string(want), body, "body should be equal") + wantTitle, err := os.ReadFile(titleGoldenFile) + require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes") + + require.Equal(t, string(wantBody), body, "body should be equal") + require.Equal(t, string(wantTitle), title, "title should be equal") }) } } From 14ad9e84e216d60fe764d60e8e0d63e7dc356bdf Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 17:41:47 +0200 Subject: [PATCH 21/24] fix --- coderd/notifications/events.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/coderd/notifications/events.go b/coderd/notifications/events.go index f043d86065023..6ba88c239edc8 100644 --- a/coderd/notifications/events.go +++ b/coderd/notifications/events.go @@ -29,6 +29,4 @@ var ( // Template-related events. var ( TemplateTemplateDeleted = uuid.MustParse("29a09665-2a4c-403f-9648-54301670e7be") - - TemplateWorkspaceBuildSummary = uuid.MustParse("bc0d9b9c-6dca-40a7-a209-fb2681e3341a") ) From 7587abc256a7c787fcb3e1fed9dad993058efcd5 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 17:44:32 +0200 Subject: [PATCH 22/24] split --- coderd/notifications/notifications_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index d927ba3e2385a..c68d5b7efb554 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -17,6 +17,7 @@ import ( "path/filepath" "slices" "sort" + "strings" "sync" "sync/atomic" "testing" @@ -884,8 +885,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) { require.NoError(t, err, "failed to render notification body template") require.NotEmpty(t, body, "body should not be empty") - bodyGoldenFile := filepath.Join("testdata", "rendered-templates", t.Name()+"-body.md.golden") - titleGoldenFile := filepath.Join("testdata", "rendered-templates", t.Name()+"-title.md.golden") + partialName := strings.Split(t.Name(), "/")[1] + bodyGoldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-body.md.golden") + titleGoldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-title.md.golden") if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(bodyGoldenFile), 0o755) From f537d26797070190545e227357693d36ad24031e Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 15:46:15 +0000 Subject: [PATCH 23/24] done --- .../rendered-templates/TemplateTemplateDeleted-title.md.golden | 1 + .../TemplateUserAccountActivated-title.md.golden | 1 + .../TemplateUserAccountCreated-title.md.golden | 1 + .../TemplateUserAccountDeleted-title.md.golden | 1 + .../TemplateUserAccountSuspended-title.md.golden | 1 + .../TemplateWorkspaceAutoUpdated-title.md.golden | 1 + .../TemplateWorkspaceAutobuildFailed-title.md.golden | 1 + .../rendered-templates/TemplateWorkspaceDeleted-title.md.golden | 1 + .../rendered-templates/TemplateWorkspaceDormant-title.md.golden | 1 + .../TemplateWorkspaceManualBuildFailed-title.md.golden | 1 + .../TemplateWorkspaceMarkedForDeletion-title.md.golden | 1 + .../TemplateYourAccountActivated-title.md.golden | 1 + .../TemplateYourAccountSuspended-title.md.golden | 1 + 13 files changed, 13 insertions(+) create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden new file mode 100644 index 0000000000000..c3f3db7645422 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden @@ -0,0 +1 @@ +Template "bobby-template" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden new file mode 100644 index 0000000000000..ebf8e9da36934 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden @@ -0,0 +1 @@ +User account "bobby" activated \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden new file mode 100644 index 0000000000000..bfcdf6826f772 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden @@ -0,0 +1 @@ +User account "bobby" created \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden new file mode 100644 index 0000000000000..199d4ddd66d12 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden @@ -0,0 +1 @@ +User account "bobby" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden new file mode 100644 index 0000000000000..f2be8e201f0af --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden @@ -0,0 +1 @@ +User account "bobby" suspended \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden new file mode 100644 index 0000000000000..fb62dcd0d3692 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" updated automatically \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden new file mode 100644 index 0000000000000..9cf98bc9e546a --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" autobuild failed \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden new file mode 100644 index 0000000000000..6806624053eb9 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden new file mode 100644 index 0000000000000..ce34a2a029ab4 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" marked as dormant \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden new file mode 100644 index 0000000000000..e786626b74672 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" manual build failed \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden new file mode 100644 index 0000000000000..1b561a73678de --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden @@ -0,0 +1 @@ +Workspace "bobby-workspace" marked for deletion \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden new file mode 100644 index 0000000000000..90be1ef2dd63c --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden @@ -0,0 +1 @@ +Your account "bobby" has been activated \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden new file mode 100644 index 0000000000000..3a4cb57c8aac0 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden @@ -0,0 +1 @@ +Your account "bobby" has been suspended \ No newline at end of file From 47c387bf61fbf56c145cb23615be3d5c6c98ba44 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Wed, 4 Sep 2024 15:48:33 +0000 Subject: [PATCH 24/24] fmt --- coderd/notifications/notifications_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index c68d5b7efb554..567866a0aaf35 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -892,9 +892,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) { if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(bodyGoldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(bodyGoldenFile, []byte(body), 0600) + err = os.WriteFile(bodyGoldenFile, []byte(body), 0o600) require.NoError(t, err, "want no error writing body golden file") - err = os.WriteFile(titleGoldenFile, []byte(title), 0600) + err = os.WriteFile(titleGoldenFile, []byte(title), 0o600) require.NoError(t, err, "want no error writing title golden file") return }