-
Notifications
You must be signed in to change notification settings - Fork 6
/
config_test.go
92 lines (73 loc) · 2.49 KB
/
config_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package mistralmail
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestConfigWithoutHostname(t *testing.T) {
Convey("When HOSTNAME is empty", t, func() {
t.Setenv("HOSTNAME", "")
t.Setenv("HTTP_ADDRESS", ":8080")
t.Setenv("METRICS_ADDRESS", ":9000")
t.Setenv("SECRET", "some-secret")
t.Setenv("TLS_DISABLE", "true")
t.Setenv("SMTP_ADDRESS_INCOMING", "")
t.Setenv("SMTP_ADDRESS_OUTGOING", "smtp.outgoing.example.com:587")
t.Setenv("SMTP_OUTGOING_MODE", "RELAY")
t.Setenv("EXTERNAL_RELAY_HOSTNAME", "somehost")
t.Setenv("EXTERNAL_RELAY_PORT", "587")
t.Setenv("IMAP_ADDRESS", "imap.example.com:143")
t.Setenv("DATABASE_URL", "sqlite:file.db")
config, err := BuildConfigFromEnv()
So(err, ShouldBeNil)
err = config.Validate()
Convey("Then it should return an error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "HOSTNAME cannot be empty")
})
})
}
func TestConfigWithoutSecret(t *testing.T) {
Convey("When SECRET is empty", t, func() {
t.Setenv("HOSTNAME", "test")
t.Setenv("HTTP_ADDRESS", ":8080")
t.Setenv("METRICS_ADDRESS", ":9000")
t.Setenv("SECRET", "")
t.Setenv("TLS_DISABLE", "true")
t.Setenv("SMTP_ADDRESS_INCOMING", "")
t.Setenv("SMTP_ADDRESS_OUTGOING", "smtp.outgoing.example.com:587")
t.Setenv("SMTP_OUTGOING_MODE", "RELAY")
t.Setenv("EXTERNAL_RELAY_HOSTNAME", "somehost")
t.Setenv("EXTERNAL_RELAY_PORT", "587")
t.Setenv("IMAP_ADDRESS", "imap.example.com:143")
t.Setenv("DATABASE_URL", "sqlite:file.db")
config, err := BuildConfigFromEnv()
So(err, ShouldBeNil)
err = config.Validate()
Convey("Then it should return an error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "SECRET cannot be empty")
})
})
}
func TestConfig(t *testing.T) {
Convey("When all required fields are set", t, func() {
t.Setenv("HOSTNAME", "test")
t.Setenv("HTTP_ADDRESS", ":8080")
t.Setenv("METRICS_ADDRESS", ":9000")
t.Setenv("SECRET", "some-secret")
t.Setenv("TLS_DISABLE", "true")
t.Setenv("SMTP_ADDRESS_INCOMING", "")
t.Setenv("SMTP_ADDRESS_OUTGOING", "smtp.outgoing.example.com:587")
t.Setenv("SMTP_OUTGOING_MODE", "RELAY")
t.Setenv("EXTERNAL_RELAY_HOSTNAME", "somehost")
t.Setenv("EXTERNAL_RELAY_PORT", "587")
t.Setenv("IMAP_ADDRESS", "imap.example.com:143")
t.Setenv("DATABASE_URL", "sqlite:file.db")
config, err := BuildConfigFromEnv()
So(err, ShouldBeNil)
err = config.Validate()
Convey("Then it should not return an error", func() {
So(err, ShouldBeNil)
})
})
}