-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
68 lines (61 loc) · 1.13 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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
var baseConfig = Config{
Hostname: "http://localhost",
Token: "token",
Smtp: Smtp{
Host: "smtp.host.com",
Port: 587,
FromEmail: "from@email.com",
Password: "password",
ToEmails: []string{"to@email.com"},
Subject: "Test Subject",
Insecure: false,
},
Environment: "production",
}
func TestConfigIsValid(t *testing.T) {
s := setup(t)
defer stop(t, s)
tests := []struct {
name string
config func() Config
pass bool
}{
{
name: "should create valid config",
config: func() Config {
cfg := baseConfig
cfg.Hostname = s.Url
cfg.Token = s.Token
return cfg
},
pass: true,
},
{
name: "should not create invalid config",
config: func() Config {
cfg := baseConfig
cfg.Token = ""
return cfg
},
pass: false,
},
}
for i, tt := range tests {
test := func(t *testing.T) {
t.Logf("When testing #%d: %s", i, tt.name)
cfg := tt.config()
err := cfg.IsValid()
if tt.pass {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
}
t.Run(tt.name, test)
}
}