-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
69 lines (54 loc) · 1.66 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
package main
import (
"io"
"os"
"testing"
"github.com/stretchr/testify/suite"
log "github.com/sirupsen/logrus"
)
type ConfigTestSuite struct {
suite.Suite
}
func (s *ConfigTestSuite) SetupTest() {
log.SetOutput(io.Discard)
}
func (s *ConfigTestSuite) TestNewConfig() {
s.Run("fail when userli token not set", func() {
defer func() { log.StandardLogger().ExitFunc = nil }()
var fatal bool
log.StandardLogger().ExitFunc = func(int) { fatal = true }
_ = NewConfig()
s.True(fatal)
})
s.Run("default config", func() {
os.Setenv("USERLI_TOKEN", "token")
config := NewConfig()
s.Equal("token", config.UserliToken)
s.Equal("http://localhost:8000", config.UserliBaseURL)
s.Equal(":10001", config.AliasListenAddr)
s.Equal(":10002", config.DomainListenAddr)
s.Equal(":10003", config.MailboxListenAddr)
s.Equal(":10004", config.SendersListenAddr)
s.Equal(":10005", config.MetricsListenAddr)
})
s.Run("custom config", func() {
os.Setenv("USERLI_TOKEN", "token")
os.Setenv("USERLI_BASE_URL", "http://example.com")
os.Setenv("ALIAS_LISTEN_ADDR", ":20001")
os.Setenv("DOMAIN_LISTEN_ADDR", ":20002")
os.Setenv("MAILBOX_LISTEN_ADDR", ":20003")
os.Setenv("SENDERS_LISTEN_ADDR", ":20004")
os.Setenv("METRICS_LISTEN_ADDR", ":20005")
config := NewConfig()
s.Equal("token", config.UserliToken)
s.Equal("http://example.com", config.UserliBaseURL)
s.Equal(":20001", config.AliasListenAddr)
s.Equal(":20002", config.DomainListenAddr)
s.Equal(":20003", config.MailboxListenAddr)
s.Equal(":20004", config.SendersListenAddr)
s.Equal(":20005", config.MetricsListenAddr)
})
}
func TestConfig(t *testing.T) {
suite.Run(t, new(ConfigTestSuite))
}