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

Skip to content

Commit 222892b

Browse files
committed
chore: fix notifications test
also a test that was broken from an earlier fix Signed-off-by: Danny Kopping <[email protected]>
1 parent a66559f commit 222892b

File tree

3 files changed

+168
-2
lines changed

3 files changed

+168
-2
lines changed

coderd/notifications/notifications_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import (
3535
"golang.org/x/xerrors"
3636

3737
"cdr.dev/slog"
38+
"github.com/coder/quartz"
39+
"github.com/coder/serpent"
40+
3841
"github.com/coder/coder/v2/coderd/coderdtest"
3942
"github.com/coder/coder/v2/coderd/database"
4043
"github.com/coder/coder/v2/coderd/database/dbauthz"
@@ -48,8 +51,6 @@ import (
4851
"github.com/coder/coder/v2/coderd/util/syncmap"
4952
"github.com/coder/coder/v2/codersdk"
5053
"github.com/coder/coder/v2/testutil"
51-
"github.com/coder/quartz"
52-
"github.com/coder/serpent"
5354
)
5455

5556
// updateGoldenFiles is a flag that can be set to update golden files.
@@ -1226,6 +1227,25 @@ func TestNotificationTemplates_Golden(t *testing.T) {
12261227
Labels: map[string]string{},
12271228
},
12281229
},
1230+
{
1231+
name: "TemplateWorkspaceResourceReplaced",
1232+
id: notifications.TemplateWorkspaceResourceReplaced,
1233+
payload: types.MessagePayload{
1234+
UserName: "Bobby",
1235+
UserEmail: "[email protected]",
1236+
UserUsername: "bobby",
1237+
Labels: map[string]string{
1238+
"workspace": "my-workspace",
1239+
"workspace_build_num": "2",
1240+
"claimant": "prebuilds-claimer",
1241+
},
1242+
Data: map[string]any{
1243+
"replacements": map[string]string{
1244+
"docker_container[0]": "env, hostname",
1245+
},
1246+
},
1247+
},
1248+
},
12291249
}
12301250

12311251
// We must have a test case for every notification_template. This is enforced below:
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
3+
Subject: There might be a problem with a recently claimed prebuilt workspace
4+
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
5+
Date: Fri, 11 Oct 2024 09:03:06 +0000
6+
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
7+
MIME-Version: 1.0
8+
9+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
10+
Content-Transfer-Encoding: quoted-printable
11+
Content-Type: text/plain; charset=UTF-8
12+
13+
Hi Bobby,
14+
15+
Workspace my-workspace was claimed from a prebuilt workspace by prebuilds-c=
16+
laimer.
17+
During the claim, Terraform destroyed and recreated the following resources
18+
because one or more immutable attributes changed:
19+
20+
docker_container[0] was replaced due to changes to env, hostname
21+
22+
When Terraform must change an immutable attribute, it replaces the entire r=
23+
esource.
24+
If you=E2=80=99re using prebuilds to speed up provisioning, unexpected repl=
25+
acements will slow down
26+
workspace startup=E2=80=94even when claiming a prebuilt environment.
27+
28+
For tips on preventing replacements and improving claim performance, see th=
29+
is guide (https://coder.com/docs/TODO).
30+
31+
32+
View workspace build: http://test.com/@prebuilds-claimer/my-workspace/build=
33+
s/2
34+
35+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
36+
Content-Transfer-Encoding: quoted-printable
37+
Content-Type: text/html; charset=UTF-8
38+
39+
<!doctype html>
40+
<html lang=3D"en">
41+
<head>
42+
<meta charset=3D"UTF-8" />
43+
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
44+
=3D1.0" />
45+
<title>There might be a problem with a recently claimed prebuilt worksp=
46+
ace</title>
47+
</head>
48+
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
49+
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
50+
l', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617=
51+
; background: #f8fafc;">
52+
<div style=3D"max-width: 600px; margin: 20px auto; padding: 60px; borde=
53+
r: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-alig=
54+
n: left; font-size: 14px; line-height: 1.5;">
55+
<div style=3D"text-align: center;">
56+
<img src=3D"https://coder.com/coder-logo-horizontal.png" alt=3D"Cod=
57+
er Logo" style=3D"height: 40px;" />
58+
</div>
59+
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
60+
argin: 8px 0 32px; line-height: 1.5;">
61+
There might be a problem with a recently claimed prebuilt workspace
62+
</h1>
63+
<div style=3D"line-height: 1.5;">
64+
<p>Hi Bobby,</p>
65+
<p>Workspace <strong>my-workspace</strong> was claimed from a prebu=
66+
ilt workspace by <strong>prebuilds-claimer</strong>.<br>
67+
During the claim, Terraform destroyed and recreated the following resources=
68+
<br>
69+
because one or more immutable attributes changed:</p>
70+
71+
<ul>
72+
<li>_docker<em>container[0]</em> was replaced due to changes to <em>env, h=
73+
ostname</em><br>
74+
</li>
75+
</ul>
76+
77+
<p>When Terraform must change an immutable attribute, it replaces the entir=
78+
e resource.<br>
79+
If you=E2=80=99re using prebuilds to speed up provisioning, unexpected repl=
80+
acements will slow down<br>
81+
workspace startup=E2=80=94even when claiming a prebuilt environment.</p>
82+
83+
<p>For tips on preventing replacements and improving claim performance, see=
84+
<a href=3D"https://coder.com/docs/TODO">this guide</a>.</p>
85+
</div>
86+
<div style=3D"text-align: center; margin-top: 32px;">
87+
=20
88+
<a href=3D"http://test.com/@prebuilds-claimer/my-workspace/builds/2=
89+
" style=3D"display: inline-block; padding: 13px 24px; background-color: #02=
90+
0617; color: #f8fafc; text-decoration: none; border-radius: 8px; margin: 0 =
91+
4px;">
92+
View workspace build
93+
</a>
94+
=20
95+
</div>
96+
<div style=3D"border-top: 1px solid #e2e8f0; color: #475569; font-siz=
97+
e: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
98+
<p>&copy;&nbsp;2024&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a =
99+
href=3D"http://test.com" style=3D"color: #2563eb; text-decoration: none;">h=
100+
ttp://test.com</a></p>
101+
<p><a href=3D"http://test.com/settings/notifications" style=3D"colo=
102+
r: #2563eb; text-decoration: none;">Click here to manage your notification =
103+
settings</a></p>
104+
<p><a href=3D"http://test.com/settings/notifications?disabled=3D89d=
105+
9745a-816e-4695-a17f-3d0a229e2b8d" style=3D"color: #2563eb; text-decoration=
106+
: none;">Stop receiving emails like this</a></p>
107+
</div>
108+
</div>
109+
</body>
110+
</html>
111+
112+
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4--
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"_version": "1.1",
3+
"msg_id": "00000000-0000-0000-0000-000000000000",
4+
"payload": {
5+
"_version": "1.2",
6+
"notification_name": "Prebuilt Workspace Resource Replaced",
7+
"notification_template_id": "00000000-0000-0000-0000-000000000000",
8+
"user_id": "00000000-0000-0000-0000-000000000000",
9+
"user_email": "[email protected]",
10+
"user_name": "Bobby",
11+
"user_username": "bobby",
12+
"actions": [
13+
{
14+
"label": "View workspace build",
15+
"url": "http://test.com/@prebuilds-claimer/my-workspace/builds/2"
16+
}
17+
],
18+
"labels": {
19+
"claimant": "prebuilds-claimer",
20+
"workspace": "my-workspace",
21+
"workspace_build_num": "2"
22+
},
23+
"data": {
24+
"replacements": {
25+
"docker_container[0]": "env, hostname"
26+
}
27+
},
28+
"targets": null
29+
},
30+
"title": "There might be a problem with a recently claimed prebuilt workspace",
31+
"title_markdown": "There might be a problem with a recently claimed prebuilt workspace",
32+
"body": "Workspace my-workspace was claimed from a prebuilt workspace by prebuilds-claimer.\nDuring the claim, Terraform destroyed and recreated the following resources\nbecause one or more immutable attributes changed:\n\ndocker_container[0] was replaced due to changes to env, hostname\n\nWhen Terraform must change an immutable attribute, it replaces the entire resource.\nIf you’re using prebuilds to speed up provisioning, unexpected replacements will slow down\nworkspace startup—even when claiming a prebuilt environment.\n\nFor tips on preventing replacements and improving claim performance, see this guide (https://coder.com/docs/TODO).",
33+
"body_markdown": "\nWorkspace **my-workspace** was claimed from a prebuilt workspace by **prebuilds-claimer**.\nDuring the claim, Terraform destroyed and recreated the following resources\nbecause one or more immutable attributes changed:\n\n- _docker_container[0]_ was replaced due to changes to _env, hostname_\n\n\nWhen Terraform must change an immutable attribute, it replaces the entire resource.\nIf you’re using prebuilds to speed up provisioning, unexpected replacements will slow down\nworkspace startup—even when claiming a prebuilt environment.\n\nFor tips on preventing replacements and improving claim performance, see [this guide](https://coder.com/docs/TODO).\n"
34+
}

0 commit comments

Comments
 (0)