(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func 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 { |
nothing calls this directly
no test coverage detected