Skip to content

Commit 5fd03b3

Browse files
test: notifications.Enabled()
1 parent 77d1803 commit 5fd03b3

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

codersdk/deployment_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,69 @@ func TestPremiumSuperSet(t *testing.T) {
568568
require.NotContains(t, enterprise.Features(), "", "enterprise should not contain empty string")
569569
require.NotContains(t, premium.Features(), "", "premium should not contain empty string")
570570
}
571+
572+
func TestNotificationsCanBeDisabled(t *testing.T) {
573+
t.Parallel()
574+
575+
tests := []struct {
576+
name string
577+
expectNotificationsEnabled bool
578+
environment []serpent.EnvVar
579+
}{
580+
{
581+
name: "NoDeliveryMethodSet",
582+
environment: []serpent.EnvVar{},
583+
expectNotificationsEnabled: false,
584+
},
585+
{
586+
name: "SMTP_DeliveryMethodSet",
587+
environment: []serpent.EnvVar{
588+
{
589+
Name: "CODER_EMAIL_SMARTHOST",
590+
Value: "localhost:587",
591+
},
592+
},
593+
expectNotificationsEnabled: true,
594+
},
595+
{
596+
name: "Webhook_DeliveryMethodSet",
597+
environment: []serpent.EnvVar{
598+
{
599+
Name: "CODER_NOTIFICATIONS_WEBHOOK_ENDPOINT",
600+
Value: "https://example.com/webhook",
601+
},
602+
},
603+
expectNotificationsEnabled: true,
604+
},
605+
{
606+
name: "WebhookAndSMTP_DeliveryMethodSet",
607+
environment: []serpent.EnvVar{
608+
{
609+
Name: "CODER_NOTIFICATIONS_WEBHOOK_ENDPOINT",
610+
Value: "https://example.com/webhook",
611+
},
612+
{
613+
Name: "CODER_EMAIL_SMARTHOST",
614+
Value: "localhost:587",
615+
},
616+
},
617+
expectNotificationsEnabled: true,
618+
},
619+
}
620+
621+
for _, tt := range tests {
622+
tt := tt
623+
624+
t.Run(tt.name, func(t *testing.T) {
625+
t.Parallel()
626+
627+
dv := codersdk.DeploymentValues{}
628+
opts := dv.Options()
629+
630+
err := opts.ParseEnv(tt.environment)
631+
require.NoError(t, err)
632+
633+
require.Equal(t, tt.expectNotificationsEnabled, dv.Notifications.Enabled())
634+
})
635+
}
636+
}

0 commit comments

Comments
 (0)