-
Notifications
You must be signed in to change notification settings - Fork 102
/
admin_setting_smtp_integration_test.go
71 lines (57 loc) · 1.85 KB
/
admin_setting_smtp_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAdminSettings_SMTP_Read(t *testing.T) {
skipUnlessEnterprise(t)
client := testClient(t)
ctx := context.Background()
smtpSettings, err := client.Admin.Settings.SMTP.Read(ctx)
require.NoError(t, err)
assert.Equal(t, "smtp", smtpSettings.ID)
assert.NotNil(t, smtpSettings.Enabled)
assert.NotNil(t, smtpSettings.Host)
assert.NotNil(t, smtpSettings.Port)
assert.NotNil(t, smtpSettings.Sender)
assert.NotNil(t, smtpSettings.Auth)
assert.NotNil(t, smtpSettings.Username)
}
func TestAdminSettings_SMTP_Update(t *testing.T) {
skipUnlessEnterprise(t)
client := testClient(t)
ctx := context.Background()
enabled := true
disabled := false
t.Run("with Auth option defined", func(t *testing.T) {
smtpSettings, err := client.Admin.Settings.SMTP.Update(ctx, AdminSMTPSettingsUpdateOptions{
Enabled: Bool(disabled),
Auth: SMTPAuthValue(SMTPAuthNone),
})
require.NoError(t, err)
assert.Equal(t, disabled, smtpSettings.Enabled)
})
t.Run("with no Auth option", func(t *testing.T) {
smtpSettings, err := client.Admin.Settings.SMTP.Update(ctx, AdminSMTPSettingsUpdateOptions{
Enabled: Bool(disabled),
TestEmailAddress: String("[email protected]"),
Host: String("123"),
Port: Int(123),
})
require.NoError(t, err)
assert.Equal(t, SMTPAuthNone, smtpSettings.Auth)
assert.Equal(t, disabled, smtpSettings.Enabled)
})
t.Run("with invalid Auth option", func(t *testing.T) {
var SMTPAuthPlained SMTPAuthType = "plained"
_, err := client.Admin.Settings.SMTP.Update(ctx, AdminSMTPSettingsUpdateOptions{
Enabled: Bool(enabled),
Auth: &SMTPAuthPlained,
})
assert.Equal(t, err, ErrInvalidSMTPAuth)
})
}