| 1056 | } |
| 1057 | |
| 1058 | func TestNotificationsCanBeDisabled(t *testing.T) { |
| 1059 | t.Parallel() |
| 1060 | |
| 1061 | tests := []struct { |
| 1062 | name string |
| 1063 | expectNotificationsEnabled bool |
| 1064 | environment []serpent.EnvVar |
| 1065 | }{ |
| 1066 | { |
| 1067 | name: "NoDeliveryMethodSet", |
| 1068 | environment: []serpent.EnvVar{}, |
| 1069 | expectNotificationsEnabled: false, |
| 1070 | }, |
| 1071 | { |
| 1072 | name: "SMTP_DeliveryMethodSet", |
| 1073 | environment: []serpent.EnvVar{ |
| 1074 | { |
| 1075 | Name: "CODER_EMAIL_SMARTHOST", |
| 1076 | Value: "localhost:587", |
| 1077 | }, |
| 1078 | }, |
| 1079 | expectNotificationsEnabled: true, |
| 1080 | }, |
| 1081 | { |
| 1082 | name: "Webhook_DeliveryMethodSet", |
| 1083 | environment: []serpent.EnvVar{ |
| 1084 | { |
| 1085 | Name: "CODER_NOTIFICATIONS_WEBHOOK_ENDPOINT", |
| 1086 | Value: "https://example.com/webhook", |
| 1087 | }, |
| 1088 | }, |
| 1089 | expectNotificationsEnabled: true, |
| 1090 | }, |
| 1091 | { |
| 1092 | name: "WebhookAndSMTP_DeliveryMethodSet", |
| 1093 | environment: []serpent.EnvVar{ |
| 1094 | { |
| 1095 | Name: "CODER_NOTIFICATIONS_WEBHOOK_ENDPOINT", |
| 1096 | Value: "https://example.com/webhook", |
| 1097 | }, |
| 1098 | { |
| 1099 | Name: "CODER_EMAIL_SMARTHOST", |
| 1100 | Value: "localhost:587", |
| 1101 | }, |
| 1102 | }, |
| 1103 | expectNotificationsEnabled: true, |
| 1104 | }, |
| 1105 | } |
| 1106 | |
| 1107 | for _, tt := range tests { |
| 1108 | t.Run(tt.name, func(t *testing.T) { |
| 1109 | t.Parallel() |
| 1110 | |
| 1111 | dv := codersdk.DeploymentValues{} |
| 1112 | opts := dv.Options() |
| 1113 | |
| 1114 | err := opts.ParseEnv(tt.environment) |
| 1115 | require.NoError(t, err) |