MCPcopy Index your code
hub / github.com/coder/coder / TestGoTemplate

Function TestGoTemplate

coderd/notifications/render/gotmpl_test.go:12–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestGoTemplate(t *testing.T) {
13 t.Parallel()
14
15 const userEmail = "bob@xyz.com"
16
17 tests := []struct {
18 name string
19 in string
20 payload types.MessagePayload
21 expectedOutput string
22 expectedErr error
23 }{
24 {
25 name: "top-level variables are accessible and substituted",
26 in: "{{ .UserEmail }}",
27 payload: types.MessagePayload{UserEmail: userEmail},
28 expectedOutput: userEmail,
29 expectedErr: nil,
30 },
31 {
32 name: "input labels are accessible and substituted",
33 in: "{{ .Labels.user_email }}",
34 payload: types.MessagePayload{Labels: map[string]string{
35 "user_email": userEmail,
36 }},
37 expectedOutput: userEmail,
38 expectedErr: nil,
39 },
40 {
41 name: "render workspace URL",
42 in: `[{
43 "label": "View workspace",
44 "url": "{{ base_url }}/@{{.UserUsername}}/{{.Labels.name}}"
45 }]`,
46 payload: types.MessagePayload{
47 UserName: "John Doe",
48 UserUsername: "johndoe",
49 Labels: map[string]string{
50 "name": "my-workspace",
51 },
52 },
53 expectedOutput: `[{
54 "label": "View workspace",
55 "url": "https://mocked-server-address/@johndoe/my-workspace"
56 }]`,
57 },
58 {
59 name: "render notification template ID",
60 in: `{{ .NotificationTemplateID }}`,
61 payload: types.MessagePayload{
62 NotificationTemplateID: "4e19c0ac-94e1-4532-9515-d1801aa283b2",
63 },
64 expectedOutput: "4e19c0ac-94e1-4532-9515-d1801aa283b2",
65 expectedErr: nil,
66 },
67 }
68
69 for _, tc := range tests {

Callers

nothing calls this directly

Calls 3

GoTemplateFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected